Convert between cv :: Mat and arma :: mat

I use OpenCV and also want to add some of the interesting features from mlpack , which uses Armadillo .

Is there an easy way to sparkle between cv :: Mat and the :: mat weapon?

Thanks!

+8
type-conversion opencv armadillo mlpack
source share
1 answer

OpenCV Mat has a pointer to its data. Armadillo has a constructor that can read from external data. Easy to put them together. Remember that Armadillo is stored in the main order, while OpenCV uses a series of lines. I suppose you will need to add another step to convert before or after.

 cv::Mat opencv_mat; //opencv mat, already transposed. arma::mat arma_mat( reinterpret_cast<double*>opencv_mat.data, opencv_mat.rows, opencv_mat.cols ) 

The cv::Mat constructor has a form that takes a pointer to the data, and arma::mat has a function for double * pointers to its data, called memptr ().

So, if you want to convert from arma::mat to cv::Mat , this should work:

 cv::Mat opencv_mat( rows, cols, CV_64FC1, arma_mat.memptr() ) 
+10
source share

All Articles