Reputation: 5019
This post show us how to map the cv::Mat
to Eigen matrix without copy the data, it works fine, but there are one thing I do not understand.
Mat A(20, 20, CV_32FC1);
cv::randn(A, 0.0f, 1.0f); // random data
// Map the OpenCV matrix with Eigen:
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> A_Eigen(A.ptr<float>(), A.rows, A.cols);
The problem is, the Mat A
do not tell the A_Eigen
how many bytes per row it should take, as far as I know the cv::Mat
of OpenCV may or may not do padding on each row, do I need to tell the Eigen how many bytes per row (how?)?, or I can safely omit it?
Ps: I am using Eigen 3
Upvotes: 0
Views: 1545
Reputation: 10596
Instead of using A.cols
, use A.step
(or A.step[0]
or A.step[1]
?). If the OpenCV matrix is not continuous, then m.step != m.cols*m.elemSize()
. You'll just have to ignore any additional columns, e.g. with A_Eigen.block<0,0>(A.rows, A.cols)
.
Upvotes: 1