开发者

EmguCV - Create image from unmanaged data

开发者 https://www.devze.com 2023-03-03 20:09 出处:网络
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. The best constructor I

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. 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. 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). I can just guess but don't try to use the matrix's _ptr pointer. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号