cv :: Mat和arma :: mat之间的转换 [英] Conversion between cv::Mat and arma::mat

查看:439
本文介绍了cv :: Mat和arma :: mat之间的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenCV,并且还想从 mlpack (使用 Armadillo 矩阵.

I am using OpenCV and also want to add some of cool functions from mlpack, which is using Armadillo matrices.

在cv :: Mat和arms :: mat之间有一种简单的迷恋方法吗?

Is there an easy way to convet between cv::Mat and arms::mat?

谢谢!

推荐答案

OpenCV的Mat具有指向其数据的指针. Armadillo具有能够从外部数据读取的构造函数.将它们放在一起很容易.请记住,Armadillo以列优先顺序存储,而OpenCV使用行优先顺序存储.我想您需要在转换之前或之后添加另一步进行转换.

OpenCV's Mat has a pointer to its data. Armadillo has a constructor that is capable of reading from external data. It's easy to put them together. Remember that Armadillo stores in column-major order, whereas OpenCV uses row-major. I suppose you'll need to add another step for transformation, before or after.

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

cv::Mat构造函数具有接受数据指针的形式,而arma::mat具有指向其数据的double *指针的函数memptr().

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

因此,如果您想从arma::mat转换为cv::Mat,这应该可以:

So, if you'd like to convert from arma::mat to cv::Mat, this should work:

cv::Mat opencv_mat( rows, cols, CV_64FC1, arma_mat.memptr() )

这篇关于cv :: Mat和arma :: mat之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆