Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate matrix Eigen library

Tags:

c++

eigen

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"
like image 779
Taras Novokhatskiy Avatar asked Jul 23 '26 09:07

Taras Novokhatskiy


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();
like image 158
J'e Avatar answered Jul 25 '26 23:07

J'e



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!