Вы находитесь на странице: 1из 2

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.Util;
namespace CameraCapture
{
public partial class CameraCapture : Form
{
//declaring global variables
private Capture capture; //takes images from camera as image fram
es
private bool captureInProgress;
public CameraCapture()
{
InitializeComponent();
}
//----------------------------------------------------------------------
--------//
//Process Frame() below is our user defined function in which we will cr
eate 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;
}
//btnStart_Click() function is the one that handles our "Start!" button'
click
//event. it creates a new capture object if its not created already. e.g
at first time
//starting. once the capture is created, it checks if the capture is sti
ll in progress,
//if so the
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 b
utton 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();
}
}
}

Вам также может понравиться