创建一根按钮并命名为btnOpenAVI:
双击按钮并添加如下代码:
private void btnOpenAVI_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "AVI文件|*.avi";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
CvInvoke.cvNamedWindow("打开视频");
IntPtr capture=CvInvoke.cvCreateFileCapture(openFileDialog.FileName);
this.video = capture;
IntPtr frame = new IntPtr();
while (true)
{
frame = CvInvoke.cvQueryFrame(capture);
CvInvoke.cvShowImage("打开视频", frame);
//if (!frame) break;
int c = CvInvoke.cvWaitKey(20);
if (c == 13) break;
}
//this.video = capture;
CvInvoke.cvWaitKey(0);
CvInvoke.cvReleaseCapture(ref capture);
CvInvoke.cvDestroyWindow("打开视频");
}
}