标签:
打开视频的思路跟打开图片的思路是一样的,只不过视频是由一帧帧图片组成,因此,打开视频的处理程序有一个连续的获取图片并逐帧显示的处理过程。GUI同《浅入浅出EmguCv(二)EmguCv打开指定图片》一样,只不过处理程序编程如下所示:
1 /// <summary> 2 /// 点击按钮打开指定图片 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void OpenImage_Click(object sender, EventArgs e) 7 { 8 OpenFileDialog openFileDialog = new OpenFileDialog(); 9 if (openFileDialog.ShowDialog() == DialogResult.OK) 10 { 11 try 12 { 13 capture = new Capture(openFileDialog.FileName); 14 fps = (int)capture.GetCaptureProperty(CapProp.Fps); 15 Application.Idle += new EventHandler(ProcessFrame); 16 } 17 catch (Exception exp) 18 { 19 MessageBox.Show(exp.Message); 20 } 21 22 23 } 24 } 25 private void ProcessFrame(object sender, EventArgs e) 26 { 27 28 Mat frame = capture.QueryFrame(); 29 if (frame != null) 30 { 31 //为使播放顺畅,添加以下延时 32 System.Threading.Thread.Sleep((int)(1000.0 /fps-5)); 33 picWindow.Image = frame; 34 35 } 36 GC.Collect(); 37 }
编译运行,打开视频如图所示:
标签:
原文地址:http://www.cnblogs.com/snipergodson/p/5872940.html