简体   繁体   English

EmguCV-从非托管数据创建图像

[英]EmguCV - Create image from unmanaged data

I'm using EmguCV and i've got a byte type Grayscale Matrix with the size of 640x480 and Every element of the matrix is either 255 or 0. Now I need to make an Image from this. 我正在使用EmguCV,并且具有640x480大小的字节类型的灰度矩阵,并且矩阵的每个元素都是255或0。现在我需要从中制作一个图像。 The best constructor I found looked like this: 我发现的最佳构造函数如下所示:

Image<Gray,byte>(int width, int height, int stride, IntPtr scan0)

I got the first, second and fourth parameters from the matrix and I sent 640 for the stride. 我从矩阵中获得了第一,第二和第四参数,并为步幅发送了640。 But it gives me an 但这给了我一个

Access violation exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I'll appreciate any help. 我将不胜感激。

You most likely passed something wrong as the pointer. 您很可能传递了一些错误的指针。 A wrong stride would just result in the image contents appearing distorted. 错误的步幅只会导致图像内容失真。 640 would be the correct value in your case (just use width again) as the stride always represents the length of one image line in memory (in your case 640 bytes). 在您的情况下640将是正确的值(请再次使用宽度),因为跨度始终代表内存中一条图像行的长度(在您的情况下为640字节)。 I can just guess but don't try to use the matrix's _ptr pointer. 我只能猜测,但不要尝试使用矩阵的_ptr指针。 This might sound logical but that one will point to the whole matrix object and not just the data (you want). 这听起来似乎合乎逻辑,但是将指向整个矩阵对象,而不仅是数据(您想要的)。 Without checking right now, I'm rather sure you're able to use the matrix's copyTo() to copy the contents to an image (if that's sufficient for your use case). 现在不用检查,我很确定您可以使用矩阵的copyTo()将内容复制到图像(如果这足以满足您的用例)。

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

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