Emgu.CV调用摄像头 - (第四十八讲)
本章节给大家讲讲如何使用Emgu.CV调用摄像头进行拍照,Emgu CV是.NET平台下对OpenCV图像处理库的封装,也就是.NET版的OpenCV
VS环境下只需要安装EmguCV第三方库就行,其他的都是自动依赖安装的。

废话不多说,我们先来看下演示效果:

Form1.cs的代码如下:
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using System;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class Form1 : Form
{
ImageViewer viewer;
Capture capture;
public Form1()
{
InitializeComponent();
}
private void button_打开摄像头_Click(object sender, EventArgs e)
{
//获取摄像头
viewer = new ImageViewer();
//捕获
capture = new Capture();
Application.Idle += Application_Idle;
//显示
viewer.Show();
}
private void Application_Idle(object sender, EventArgs e)
{
//获得的图像
viewer.Image = capture.QueryFrame();
// 显示图片到pictureBox
pictureBox1.Image = capture.QueryFrame().ToImage<Bgr, Byte>().ToBitmap();
}
private void button_拍照_Click(object sender, EventArgs e)
{
pictureBox2.Image = capture.QueryFrame().ToImage<Bgr, Byte>().ToBitmap();
}
}
}