【问题标题】:How do I use the EMGUcv ImageBox control to display an image that comes from a seperate image capture event thread如何使用 EMGUcv ImageBox 控件显示来自单独的图像捕获事件线程的图像
【发布时间】:2017-09-24 10:30:17
【问题描述】:

我有一个从 USB 摄像头接收到图像时触发的事件线程。这很好用。

但是,在同一个事件捕获线程中,我想在具有 emgu ImageBox 控件的 UI 表单中显示该图像。我无法直接对ImageBox1.Image = capturedImage 编码,因为ImageBox 在UI 表单中而不是在OnImageEvent 线程中。

我是否在此处使用某种类型的 Invoke/Delegate 来跳转线程? (我还在学习使用这些)

但我在 emgu ImageBox 控件上找不到对 Invoke 的任何引用。有没有人有在这种交叉踩踏类型的应用程序中使用 emgu Imagebox 的经验?

当前代码:

' This method defines an image event. In it, the image that
' triggered the event is converted and saved before incrementing
' the count. Please see Acquisition_CSharp example for more
' in-depth comments on the acquisition of images.
Protected Overrides Sub OnImageEvent(capturedImage As ManagedImage)

    Console.WriteLine("Image event occurred...")

    ImageBox2.Image = ConvertToOpenCVMat(capturedImage)

    .
    .
    .

【问题讨论】:

  • emgu ImageBox 似乎没有。任何人都可以确认这一点
  • 您可以调用任何控件,它不一定是您要修改的那个。重要的是您调用 UI 线程。 -- 由于 EmguCV 的 ImageBox 似乎没有 Invoke 方法,您可以直接调用 表单本身Me.Invoke(<stuff here>) 或:<target form>.Invoke(<stuff here>)

标签: vb.net opencv emgucv


【解决方案1】:

将从 USB 摄像头接收到的图像数据保存到模块中的公共变量中;该变量可以直接被主线程(UI Form线程)访问来显示。您唯一需要处理的是避免两个线程之间的冲突(辅助线程想要将图像数据保存到变量中,而主线程想要从中读取;您可以使用信号量来做到这一点)。

【讨论】:

  • WinForms 和 WPF 都有线程安全的方法来处理跨线程调用。当这样做既费时又可能“不安全”时,为什么要重新发明轮子? -- 在the Stack Overflow documentation 上查看我的示例。
  • 我可以使用上述 Raffaello 方法通过保存公共变量并使用 emgu ImageBox 控件在 UI 窗体线程中显示它来使其工作。这确认我的 onImageEvent() 正在正确地从 USB 摄像头捕获图像。 -- 然而,我同意 Visual Vincent 的观点,应该有一种方法可以用 Invoke 来做到这一点,但我似乎无法找到一种方法来使用 emgu ImageBox 控件和 Invoke,任何有 emgu 知识的人都可以确认这是否可能?谢谢
猜你喜欢
  • 2012-04-13
  • 1970-01-01
  • 2017-11-16
  • 2011-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-21
  • 2017-05-12
相关资源
最近更新 更多