using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
namespace safeprojectname
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Capture _capture;
private bool _captureInProgress;
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame = _capture.QueryFrame();
imageBox1.Image = frame;
}
private void buttonOpenCapture_Click(object sender, EventArgs e)
{
#region if capture is not created, create it now
if (_capture == null)
{
try
{
_capture = new Capture(0);
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
if (_capture != null)
{
if (_captureInProgress)
{
//stop the capture
buttonOpenCapture.Text = "打开视频";
Application.Idle -= ProcessFrame;
}
else
{
//start the capture
buttonOpenCapture.Text = "关闭视频";
Application.Idle += ProcessFrame;
}
_captureInProgress = !_captureInProgress;
}
}
}
}