|
usingusing 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.Util;
using Emgu.CV.Structure;
using Emgu.CV;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
namespace 摄像头
{
public partial class Form1 : Form
{
Bitmap[] bitmap;
string file;
IntPtr vedio;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
vedio = CvInvoke.cvCreateCameraCapture(0);
if (timer1.Enabled == false)
{
this.button1.Text = "停止";
this.timer1.Enabled = true;
}
else
{
this.button1.Text = "开始";
this.timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr frame = CvInvoke.cvQueryFrame(vedio);
if ( frame!=IntPtr.Zero)
{
MIplImage iplImage = (MIplImage)Marshal.PtrToStructure(frame, typeof(MIplImage));
Emgu.CV.Image<Bgr, byte> image = new Image<Bgr, byte>(iplImage.width, iplImage.height, iplImage.widthStep, iplImage.imageData);
this.pictureBox1.Image = image.Bitmap;
}
else
{
this.button1.Text = "开始";
this.timer1.Enabled = false;
pictureBox1.Image = bitmap[0];
}
}
}
} |
|