【问题标题】:How can I get a EmguCV ImageBox image?如何获得 EmguCV ImageBox 图像?
【发布时间】:2012-04-13 07:03:04
【问题描述】:

我正在尝试为我的网络摄像头的帧选择像素颜色。所以我捕获帧然后在 ImageBox 中显示,没有任何问题。但是,当我双击 ImageBox 时尝试访问存储在 ImageBox 上的图像时,我得到了 CvException。当我尝试获取图像的像素时弹出异常。

OpenCV:无法识别或不支持的数组类型

这就是我捕获帧的方式:

// On Form Load
Application.Idle += ProcessFrame;

private void ProcessFrame(object sender, EventArgs arg)
    {
        if (cap != null)
        {
            using (Image<Bgr, byte> frame = cap.QueryFrame())
            {
                if (frame != null)
                {
                    imageFrame = frame;
                    imageBoxFrame.Image = imageFrame;

                    Bgr color = imageFrame[50, 100];
                }
            }
        }
    }

在 DoubleClick 事件中:

private void imageBoxFrame_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        if (treeViewObjects.SelectedNode is ColorNode && !isTracking)
        {
            if (imageFrame == null)
                return;

            Emgu.CV.UI.ImageBox imageBox = (Emgu.CV.UI.ImageBox)sender;
            Image<Bgr, byte> image = (Image<Bgr, byte>)imageBox.Image;

            Bgr color = image[e.X, e.Y]; // This line causes the Exception
        }
    }

显然图像不为空。 我做错了什么?也许是线程的东西?

【问题讨论】:

  • 已经有一段时间了,但您应该回答您自己的问题,这样它才会出现在“未决问题”队列中。

标签: c# opencv emgucv


【解决方案1】:

(由 OP 回答的问题和请求的答案发布。请参阅Question with no answers, but issue solved in the comments (or extended in chat)

OP 写道:

我解决了。

我只需要克隆图像,因为 using 语句会擦除图像数据。因此,在 ProcessEvent 上,我只需要将帧克隆到 imageFrame。

imageFrame = frame.Clone();

还有另一个问题。访问像素数据的正确方法是通过 [Y,X] 而不是 [X,Y]。

Bgr color = image[e.Y, e.X];

【讨论】:

    猜你喜欢
    • 2017-11-16
    • 2017-09-24
    • 2021-03-08
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多