[英]How to Display Image in Emgucv
在这里,我试图通过我使用emgucv-windows-x86 2.2.1.1150
的笔记本电脑网络摄像头在 imagebox 中显示实时图像流。 (注意:我使用的是 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();
}
}
}
找不到代码有什么问题。
但这里有一种更简单的方式来展示这个概念。
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
这个问题可能会帮助你解决你的问题。
就我而言,我曾经间歇性地获得黑色和正常照片。 问题是我的基本程序不止一次实例化 emgucv exe。 这导致笔记本电脑相机同时有多个手柄。 我确保一次只运行一个捕获进程。 这解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.