Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Well, Eigen differs from OpenCV matrices in two things:

  • Eigen use column-major ordering by default.
  • Eigen use aligned memory allocators by default.

How this affect your code

Column-major ordering will lead to incorrect result if you pass Eigen data directly to OpenCV functions. Your data will be treated as 'transposed'. Depending on your application you can either declare your Eigen types with Eigen::RowMajor option or transpose OpenCV matrix that you create from Eigen data.

Aligned memory allocators allows faster memory access during vector load/stores. This reduce memory access latency and improve performance. So if your code is math-heavy using Eigen is a really good idea. However if you map OpenCV types to Eigen using Eigen::Map remember that it assumes there is no alignment for external data.

How to map Eigen to OpenCV and back

I have made a tutorial post on mapping Eigen plain matrices and expressions to OpenCV types. In my project I switched from OpenCV to Eigen for matrix operations, so I needed a handy wrapper to pass my Eigen data to OpenCV: http://computer-vision-talks.com/articles/mapping-eigen-to-opencv/. I hope this post will help you.

Well, Eigen differs from OpenCV matrices in two things:

  • Eigen use column-major ordering by default.
  • Eigen use aligned memory allocators by default.

How this affect your code

Column-major ordering will lead to incorrect result if you pass Eigen data directly to OpenCV functions. Your data will be treated as 'transposed'. Depending on your application you can either declare your Eigen types with Eigen::RowMajor option or transpose OpenCV matrix that you create from Eigen data.

Aligned memory allocators allows faster memory access during vector load/stores. This reduce memory access latency and improve performance. So if your code is math-heavy using Eigen is a really good idea. However if you map OpenCV types to Eigen using Eigen::Map remember that it assumes there is no alignment for external data.

How to map Eigen to OpenCV and back

I have made a tutorial post on mapping Eigen plain matrices and expressions to OpenCV types. In my project I switched from OpenCV to Eigen for matrix operations, so I needed a handy wrapper to pass my Eigen data to OpenCV: http://computer-vision-talks.com/articles/mapping-eigen-to-opencv/. I hope this post will help you.