【问题标题】:How to Display Image in Emgucv如何在 Emgucv 中显示图像
【发布时间】:2020-06-26 09:43:11
【问题描述】:

在这里,我试图通过笔记本电脑网络摄像头在 imagebox 中显示实时图像流,为此我使用了emgucv-windows-x86 2.2.1.1150。 (注意:我使用的是 Windows 64 位)。

我使用的按钮最初的文本是Start!。我们想要的是当按下Start! 按钮时,相机应该开始工作并且图像流应该在我们的ImageBox 中可见。如果流已打开,则开始按钮应显示Pause,按下它应暂停流,反之亦然。

问题是,当我按下Start! 按钮时,即使完全没有错误,即使网络摄像头正在工作,它也不会显示实时流图像,而是在 ImageBox 中什么也不显示。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
namespace CameraCapture
{
  public partial class cameracapture : Form
  {
    //declaring global variables
    private Capture capture;        //takes images from camera as image frames
    private bool captureInProgress; // checks if capture is executing

    public cameracapture()
    {
      InitializeComponent();
    }
    //------------------------------------------------------------------------------//
    //Process Frame() below is our user defined function in which we will create an EmguCv 
    //type image called ImageFrame. capture a frame from camera and allocate it to our 
    //ImageFrame. then show this image in ourEmguCV imageBox
    //------------------------------------------------------------------------------//

    private void ProcessFrame(object sender, EventArgs arg)
    {
      Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
      CamImageBox.Image = ImageFrame;
    }
    private void cameracapture_Load(object sender, EventArgs e)
    {

    }

    private void btnStart_Click(object sender, EventArgs e)
    {
      #region if capture is not created, create it now
      if (capture == null)
      {
        try
        {
            capture = new Capture();
        }
        catch (NullReferenceException excpt)
        {
            MessageBox.Show(excpt.Message);
        }
      }
      #endregion

      if (capture != null)
      {
        if (captureInProgress)
        {  //if camera is getting frames then stop the capture and set button Text
            // "Start" for resuming capture
            btnStart.Text = "Start!"; //
            Application.Idle -= ProcessFrame;
        }
        else
        {
            //if camera is NOT getting frames then start the capture and set button
            // Text to "Stop" for pausing capture
            btnStart.Text = "Stop";
            Application.Idle += ProcessFrame;
        }

        captureInProgress = !captureInProgress;
    }

    }
    private void ReleaseData()
    {
      if (capture != null)
        capture.Dispose();
    }
  }
}

【问题讨论】:

  • 如果我错了,请纠正我,但我在其他地方看到过这段代码。您应该提及您的来源。

标签: c# emgucv


【解决方案1】:

找不到代码有什么问题。

here 是一种更简单的展示概念的方式。

using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using System.Drawing;
using System.Windows.Forms;

ImageViewer viewer = new ImageViewer(); //create an image viewer
Capture capture = new Capture(); //create a camera captue
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{  //run this until application closed (close button click on image viewer)
   viewer.Image = capture.QueryFrame(); //draw the image obtained from camera
});
viewer.ShowDialog(); //show the image viewer

This question 可能会帮助您解决问题。

【讨论】:

    【解决方案2】:

    就我而言,我曾经间歇性地拍摄黑色和普通照片。问题是我的基础程序不止一次实例化了 emgucv exe。这导致笔记本电脑摄像头同时出现多个手柄。我确保一次只运行一个捕获进程。这解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      相关资源
      最近更新 更多