Eigen is a C++ template library for matrix and vector operations. It is highly optimized for numeric operations and support vectorization and use aligned memory allocators.
When it comes to matrix operations, Eigen is much faster than OpenCV. However, it can be situations when it is necessary to pass Eigen data to OpenCV functions.
In this post I will show how to map Eigen data to OpenCV with easy and efficient way. No copy, minimal overhead and maximum syntax sugar:
Proposed approach does not limited to continuous memory layout - it support expression and blocks as well. If given expression has to be evaluated - it will be evaluated into temporary dense storage and then mapped to OpenCV structure: