【发布时间】: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();
}
}
}
【问题讨论】:
-
如果我错了,请纠正我,但我在其他地方看到过这段代码。您应该提及您的来源。