C++ unsigned char ** 到 opencv mat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13255480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:07:21  来源:igfitidea点击:

unsigned char ** to opencv mat

c++image-processingopencvdouble-pointer

提问by Oliver9523

I'm almost there but I can't quite understand how to convert

我快到了,但我不太明白如何转换

unsigned char ** to a cv::Mat

I know that the .data part of a cv::Mat is uchar*

我知道 cv::Mat 的 .data 部分是 uchar*

I'm using a function that returns and image in the form of...

我正在使用一个以...的形式返回和图像的函数

unsigned char ** output;

But the rest of my code uses cv::Mat's. I don't have the source for the lib I'm using either so don't really know what it's doing.

但我的其余代码使用 cv::Mat 的。我也没有我正在使用的库的来源,所以我真的不知道它在做什么。

EditThanks for the help guys, I've done this...

编辑感谢您的帮助,我已经完成了...

cv::Mat TempMat = cv::Mat(h, w, CV_8UC1, *output);
imshow("this is a test",TempMat);

but the image is black so I now need to find out if there's actually anything there or not.

但图像是黑色的,所以我现在需要找出那里是否真的有任何东西。

Sorry for lack of research i'm on a tight deadline, no it's not homework, trying to get something ready to show results to a Professor!

抱歉缺乏研究,我的截止日期很紧,不,这不是家庭作业,试图准备一些东西向教授展示结果!

回答by ArtemStorozhuk

You have to use Mat constructorwith a pointer to data:

您必须使用带有指向数据的指针的Mat 构造函数

 // constructor for matrix headers pointing to user-allocated data
    Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);
    Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);

You have to convert void**to void*and after this use it.

您必须转换void**void*并在此之后使用它。

回答by AJ_Nur

maybe you should remove *at

也许你应该删除*

cv::Mat TempMat = cv::Mat(h, w, CV_8UC1, *output);

make it just like this:

让它像这样:

cv::Mat TempMat = cv::Mat(h, w, CV_8UC1, output);