简体   繁体   English

将C ++ opencv IplImage imageData和widthStep转换为android opencv Mat

[英]Convert c++ opencv IplImage imageData and widthStep to android opencv Mat

I'm developing an android app using opencv. 我正在使用opencv开发一个Android应用程序。 I have an algorithm written in C++ which uses opencv and I am porting it to java. 我有一个用C ++编写的算法,它使用opencv,并将其移植到java。 The original code uses 'IplImage' but now I'm forced to use 'Mat'. 原始代码使用“ IplImage”,但是现在我不得不使用“ Mat”。 I managed to convert most of the code but I'm facing a problem with the following instructions: 我设法转换了大多数代码,但以下指令却遇到了问题:

IplImage *src;
src->imageData;
src->widthStep;

Can I use 我可以用吗

[JAVA - Mat]src.dataAddr()  as an equivalent for [C++ - IplImage]src ->imageData

and

[JAVA - Mat]src.step1(0) as an equivalent for [C++ - IplImage]src->widthStep ?

The only link I found inherent to this topic is this one which explains how to convert 'IplImage' to 'Mat' but still in C++. 我发现该主题固有的唯一链接是链接,它说明了如何将“ IplImage”转换为“ Mat”,但仍使用C ++。 I can't use javacv. 我不能使用javacv。

Thanks 谢谢

For depth, Mat class has a method depth() . 对于深度, Mat类具有方法depth()

The widthStep is a little tricky, because the step of Mat is not exactly the same as the widthStep in IplImage, but the multiple-of-four widthStep does not seem to be needed anymore. widthStep有点棘手,因为Mat的step长与widthStep中的widthStep并不完全相同,但是似乎不再需要4的倍数widthStep。 Here is an interesting answer to read. 是一个有趣的答案。 That said, Mat class also has a method for getting the step . 也就是说, Mat类也具有获取step的方法

About imageData , I am not sure what exactly the imageData of IplImage contained, but with Mat, you can get data from of individual pixels by looping through the matrix and using methods like get(int row, int col) . 关于imageData ,我不确定IplImage的imageData到底包含什么,但是使用Mat,您可以通过遍历矩阵并使用get(int row, int col)类的方法从单个像素获取数据。 Go through the documentation of Mat . 浏览Mat文档 I am sure you will get many options. 我相信您会得到很多选择。

In the start of the doc, there is a discussion about IplImage and Mat and how the data is saved in Mat vs that in IplImage. 在文档的开头,将讨论有关IplImage和Mat以及数据如何在Mat中与在IplImage中进行保存。 Search for 搜索

So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV 1.x. 因此,Mat中的数据布局与OpenCV 1.x中的CvMat,IplImage和CvMatND类型完全兼容。

and read around it. 并阅读它。

Also read around 还读了

Partial yet very common cases of this user-allocated data case are conversions from CvMat and IplImage to Mat. 这种由用户分配的数据案例的部分但非常常见的案例是从CvMat和IplImage到Mat的转换。 For this purpose, there are special constructors taking pointers to CvMat or IplImage and the optional flag indicating whether to copy the data or not. 为此,有一些特殊的构造函数采用指向CvMat或IplImage的指针,以及指示是否复制数据的可选标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM