【发布时间】:2018-02-27 05:37:07
【问题描述】:
我可以使用Data[,,] 访问灰度图像的每个像素,但不能对 Bgr 图像进行访问。
我写了以下代码:
Image<Bgr, byte> currentFrame = capture.QueryFrame();
Image<Gray, byte> grayFrame = currentFrame.Convert<Gray, byte>();
Byte gray = grayFrame.Data[0, 10, 0];
Byte blue = currentFrame.Data[0, 10, 0];
抛出异常:Object reference not set to an instance of an object.
我通过添加断点检查,结果是这样的:
currentFrame.Data is nul
grayFrame.Data has 3d array
gray has value 71
然后下一行导致错误
为什么应该是 3d 数组的 currentFrame.Data 为空?如何访问 Bgr 图像的 Image.Data 属性?
我正在使用 emgucv 2.2.1。 2.1版本也出现同样的问题。
感谢您的帮助
我的发现非常令人惊讶。
Image<Bgr, byte> currentFrame = capture.QueryFrame();
byte b;
try
{
b = image.Data[0, 0, 0]; //Line (A)
}
catch (Exception ex)
{ MessageBox.Show("Before Convert : "+ex.Message); }
image = image.Convert<Bgr, byte>();
try
{
b = image.Data[0, 0, 0]; //Line (B)
}
catch (Exception ex)
{ MessageBox.Show("AfterConvert : "+ex.Message); }
在上面的代码中:行 (A) 抛出异常“对象引用未设置为对象的实例”。但是添加代码后
image = image.Convert<Bgr, byte>();
Line(B) 运行平稳,没有任何异常。
有人知道为什么会这样吗?
【问题讨论】:
-
那是什么语言?那是C#吗?添加适当的标签,以便您可以从了解您的代码的人那里获得帮助。