1.0.2-學習Opencv與MFC混合編程之---爲播放AVI視頻添加滑動條

源代碼地址:http://download.csdn.net/detail/nuptboyzhb/3961642web

版本1.0.2新增內容ide

Ø  全局變量和函數的添加:函數

在CVMFCview.cpp文件中增長全局變量和全局函數spa

//-----------------全局變量和函數---------------------------------------.net

int g_slider_position=0;指針

CvCapture *g_capture;code

void onTrackbarSlide(int pos)orm

{視頻

   cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);blog

}

//--效果以下:

注意:上述全局函數,不能做爲類得成員變量的形式添加

Ø  改寫void CCVMFCView::OnPlAYAVITEST()函數

具體代碼以下:

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指針

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

                   g_capture =cvCreateFileCapture(strFileName);//由待播放的視頻名,建立CvCapture指針

                   int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);//獲得視頻中幀的總數

                   if(frames!=0)

                   {

                            cvCreateTrackbar("position",WindowName1,&g_slider_position,frames,onTrackbarSlide);

                   }

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

                   IplImage *frame;//建立圖像指針 用做顯示的圖片

                   while(1)

                   {

                            frame=cvQueryFrame(g_capture);//從g_capture 獲取一幀圖像

                            if(!frame)

                            {

                                     break;

                            }

                            cvShowImage(WindowName1,frame);

                            char c=cvWaitKey(33);//等待33毫秒,若是無按鍵,返回值c=-1。若是有按鍵,返回按鍵的ASCII值

                            g_slider_position++;//

            cvCreateTrackbar("position",WindowName1,&g_slider_position,frames,onTrackbarSlide);

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

                            {

                                     break;//按下ESc鍵,中止播放

                            }

                   }

                   cvReleaseCapture(&g_capture);

                   cvDestroyWindow(WindowName1);

         }

}

 

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

相關文章
相關標籤/搜索