1.0.1-学习Opencv与MFC混合编程之---播放AVI视频

资源源代码:http://download.csdn.net/detail/nuptboyzhb/3961639

版本1.0.1新增内容

Ø  新建菜单项,Learning OpenCV——> OpenCVr入门——>播放AVI视频。

Ø  为’ 播放AVI视频’菜单项设置属性如下:

Ø  为上述菜单项建立类向导,设置如下:

Ø  编辑代码:

代码具体如下

void CCVMFCView::OnPlAYAVITEST()

{

         // TODO: Add your command handler code here

         //郑海波 2011年12月9日

         //参考:learning opencv  Page21

         CString csFilter="AVI Files(*.AVI)|*.AVI||";

         CString strFileName;

 

         CFileDialog FileDlg(true,NULL,NULL,OFN_HIDEREADONLY,csFilter);

                                                 //  文件存盘对话框

         if (FileDlg.DoModal()==IDOK )

         {         //  选择了文件名

                   strFileName = FileDlg.m_ofn.lpstrFile;

                   if (FileDlg.m_ofn.nFileExtension == 0)

                   {  //  无文件后缀

                            strFileName = strFileName + ".avi";

                            //  加文件后缀

                   }

                   CString WindowName1="Display by CV";//创建窗口的名称

                  cvNamedWindow(WindowName1,CV_WINDOW_AUTOSIZE);//创建窗口

                   //------------------------------

                   CvCapture *capture =cvCreateFileCapture(strFileName);//由待播放的视频名,创建CvCapture指针

                   IplImage *frame;//创建图像指针 用作显示的图片

                   while(1)

                   {

                            frame=cvQueryFrame(capture);//从capture 获取一帧图像

                            if(!frame)

                            {

                                     break;

                            }

                            cvShowImage(WindowName1,frame);

                            char c=cvWaitKey(33);//等待33毫秒,如果无按键,返回值c=-1。如果有按键,返回按键的ASCII值

            if(c==27)//27是Esc按键的ASCII值

                            {

                                     break;//按下ESc键,停止播放

                            }

                   }

                   cvReleaseCapture(&capture);

                   cvDestroyWindow(WindowName1);

         }

}

 

from:http://blog.csdn.net/nupt123456789/article/details/7097890

原文地址:https://www.cnblogs.com/lidabo/p/3501295.html