本文参考:浅入浅出EmguCv(三)EmguCv打开指定视频
打开视频的思路跟打开图片的思路是一样的,只不过视频是由一帧帧图片组成,因此,打开视频的处理程序有一个连续的获取图片并逐帧显示的处理过程
一.控件
在面板中拖入一个button和一个ImageBox(注意ImageBox控件为EmguCv控件)
二.代码
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;
using Emgu.CV.UI;
using Emgu.CV.ML;
namespace EMGUCVtest
{
public partial class CameraCapture : Form
{
//declaring global variables
private VideoCapture capture;
private bool isProcess = false;
public CameraCapture()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dilog = new OpenFileDialog();
if (dilog.ShowDialog() == DialogResult.OK || dilog.ShowDialog() == DialogResult.Yes)
{
ImageViewer viewer = new ImageViewer();
VideoCapture capture = new VideoCapture(dilog.FileName);
Application.Idle += new EventHandler(delegate (object sendero, EventArgs eo)
{
Mat frame = capture.QueryFrame();
System.Threading.Thread.Sleep(1);
imageBox1.SizeMode = PictureBoxSizeMode.StretchImage;
imageBox1.Image = frame;
});
}
}
}
}