浅入浅出EmguCv(三)EmguCv打开指定视频

时间:2023-03-08 17:25:13
浅入浅出EmguCv(三)EmguCv打开指定视频

打开视频的思路跟打开图片的思路是一样的,只不过视频是由一帧帧图片组成,因此,打开视频的处理程序有一个连续的获取图片并逐帧显示的处理过程。GUI同《浅入浅出EmguCv(二)EmguCv打开指定图片》一样,只不过处理程序编程如下所示:

 /// <summary>
/// 点击按钮打开指定图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenImage_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
capture = new Capture(openFileDialog.FileName);
fps = (int)capture.GetCaptureProperty(CapProp.Fps);
Application.Idle += new EventHandler(ProcessFrame);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
} }
}
private void ProcessFrame(object sender, EventArgs e)
{ Mat frame = capture.QueryFrame();
if (frame != null)
{
//为使播放顺畅,添加以下延时
System.Threading.Thread.Sleep((int)(1000.0 /fps-));
picWindow.Image = frame; }
GC.Collect();
}

编译运行,打开视频如图所示:

浅入浅出EmguCv(三)EmguCv打开指定视频