EmguCV-从非托管数据创建图像 [英] EmguCV - Create image from unmanaged data

查看:191
本文介绍了EmguCV-从非托管数据创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EmguCV,并且我有一个字节类型的灰度矩阵,大小为640x480,矩阵的每个元素都是255或0。现在,我需要从中制作一个图像。我发现的最佳构造函数如下所示:

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)

我从矩阵中获得了第一,第二和第四参数,并为步幅发送了640 。但这给了我

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.

我将不胜感激。

推荐答案

您最有可能传递了错误的指针。错误的步幅只会导致图像内容失真。在您的情况下640将是正确的值(请再次使用宽度),因为跨度始终代表内存中一条图像行的长度(在您的情况下为640字节)。我只是猜测,但不要尝试使用矩阵的 _ptr 指针。这听起来似乎合乎逻辑,但是将指向整个矩阵对象,而不仅是数据(您想要的)。现在不用检查,我很确定您能够使用矩阵的 copyTo()将内容复制到图像中(如果这足以满足您的用例)

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

这篇关于EmguCV-从非托管数据创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆