EmguCV - Create image from unmanaged data

余生长醉 提交于 2019-12-25 12:11:37

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/5941569/emgucv-create-image-from-unmanaged-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!