OpenCV CV::Mat and Eigen::Matrix

后端 未结 5 1480
孤街浪徒
孤街浪徒 2020-11-29 00:55

Is there a reversible way to convert an OpenCV cv::Mat object to an Eigen::Matrix?

e.g., Some way of doing:

cv::Mat cvMat;
         


        
5条回答
  •  臣服心动
    2020-11-29 01:31

    You should consider using Eigen::Map to wrap OpenCV matrices in order to be used directly by the Eigen SDK. This allows you to apply almost all functionalities implemented in Eigen on matrix allocated by OpenCV

    In particular you simply instantiate an Eigen::Map providing the pointer to the cv::Mat buffer:

    //allocate memory for a 4x4 float matrix
    cv::Mat cvT(4,4,CV_32FC1); 
    
    //directly use the buffer allocated by OpenCV
    Eigen::Map eigenT( cvT.data() ); 
    

    for more information on Eigen::Map take a look at Eigen Tutorial: Map Class

提交回复
热议问题