Rotate matrix Eigen library

Viewed 473

How to rotate 2d image stored in the Eigen matrix in a clockwise direction by 90 degrees?

My code:

Eigen::Matrix<int, n, n> m;
Eigen::Rotation2D rot(90);
auto m1 = m * rot.derived();

But I receive an error:

error: static_assert failed due to requirement 'ProductIsValid || SameSizes' "INVALID_MATRIX_PRODUCT"
1 Answers

Rotating counter clockwise,

Eigen::Matrix<int, n, n> m_rotated_ninty_ccwise = m.transpose().colwise().reverse();

Rotating clockwise,

Eigen::Matrix<int, n, n> m_rotated_ninty_cwise = m.reverse().transpose().reverse();
Related