Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to initialize a Eigen Matrix from an opencv cv::Mat, or from an array which is row-major?
    primarykey
    data
    text
    <p>I found that Eigen's Matrix is default column-major, which is like MATLAB, but how do I initialize an Eigen::MatrixXd from an cv::Mat? The following code is my test. But none of them could be compiled successfully. Could someone give me some advice, please? or some other links? Thanks.</p> <pre><code> cv::Mat A_M=cv::Mat(rows, cols, CV_64FC1); double *A=(double *)A_M.data(); typedef Map&lt;MatrixXd&gt; MapMat; MapMat A_eigen(A,m,n); Eigen::Matrix&lt;double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor&gt; A_eigen; Eigen::Map&lt;Matrix&lt;double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor&gt; &gt;(A,m,n) = A_eigen; </code></pre> <p>Updated:</p> <pre><code> double *A=(double *)A_M.data();//m*n double *B=(double *)B_M.data();//n*p double *C=(double *)C_M.data();//m*p //regular Eigen Matrix Eigen::MatrixXd A_eigenMat; Eigen::MatrixXd B_eigenMat; Eigen::MatrixXd C_eigenMat; Eigen::Map&lt;Eigen::Matrix&lt;double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor&gt; &gt; A_mappedMat (A, m, n); Eigen::Map&lt;Eigen::Matrix&lt;double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor&gt; &gt; B_mappedMat (B, n, p); Eigen::Map&lt;Eigen::Matrix&lt;double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor&gt; &gt; C_mappedMat (C, m, p); // Eigen handles the conversion from row major to column major A_eigenMat = A_mappedMat; B_eigenMat = B_mappedMat; C_eigenMat = C_mappedMat; // multiplication C_eigenMat=A_eigenMat*B_eigenMat; </code></pre> <p>Then, when I output the M_C, its result is wrong. It seems the C_eigenMat didn't copy the data into M_C.data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload