视频读取速度太快

来源:互联网 发布:淘宝话费慢充 编辑:程序博客网 时间:2024/06/12 01:06

void Cs1View::OnVideoFileRead(){//"calib_3D.avi"CvCapture *pCapture =cvCreateFileCapture("gggg.avi");  IplImage *pFrame = NULL;int frames = (int) cvGetCaptureProperty( pCapture, CV_CAP_PROP_FRAME_COUNT );int numfrm = 0;int m_run = 1;frames=100;//frames=1;CClientDC pDC(this);CRect r;GetClientRect (&r);while( (numfrm < frames) & (m_run == 1) ){ pFrame = cvQueryFrame( pCapture );//str.Format(TEXT("%d"),numfrm);//AfxMessageBox(str);img1.CopyOf(pFrame);img1.DrawToHDC(pDC.GetSafeHdc() ,r);//ReleaseDC( &pDC );if (cvWaitKey(20) == 27) break;numfrm++;}m_run = 0;cvReleaseCapture(&pCapture);//ReleaseDC( &pDC );//cvReleaseImage( &pFrame );}

现在读取出来的视频速度太快,可以考虑用SetTimer函数实现在OnTimer内。

==============================

修改后:在读文件函数内使用SetTimer函数调用OnTimer函数。

void Cs1View::OnVideoFileRead(){//pCapture =cvCreateFileCapture("gggg.avi");  pCapture =cvCreateFileCapture("calib_3D.avi"); SetTimer(1,25,NULL); //定时器,定时时间和帧率一致}

OnTimer函数如下:

void Cs1View::OnTimer(UINT_PTR nIDEvent){//CClientDC pDC(this);//int key = 0;   //CvCapture* m_pcapture;//IplImage* m_frame = NULL;  //if((m_pcapture = cvCaptureFromCAM(-1)) == NULL)//{//MessageBox(TEXT("Could not initialize capturing...\n"));///*return ;*///}//if(NULL==(m_frame=cvQueryFrame(m_pcapture)))//{   //MessageBox(TEXT("不能取得."));   //}   //CRect r;//GetClientRect (&r);////img1.CopyOf(m_frame,1);//IplImage *img2=cvCreateImage(cvGetSize(m_frame),IPL_DEPTH_8U,1);////cvCvtColor(m_frame,img2,CV_RGB2GRAY);////cvSobel(img2,img2,1,0,3);//cvSmooth(img2,img2,CV_BLUR,3,3,0,0); //img1.CopyOf(m_frame);//img1.DrawToHDC(pDC.GetSafeHdc() ,r);//ReleaseDC(&pDC);//CView::OnTimer(nIDEvent);////参考硕士论文《基于mfc的opencv视频人脸检测》//"calib_3D.avi"//CvCapture *pCapture =cvCreateFileCapture("gggg.avi");  /*IplImage *pFrame;*/int frames = (int) cvGetCaptureProperty( pCapture, CV_CAP_PROP_FRAME_COUNT );//frames=1;CClientDC pDC(this);CRect r;GetClientRect (&r);pFrame = cvQueryFrame( pCapture );//str.Format(TEXT("%d"),numfrm);//AfxMessageBox(str);img1.CopyOf(pFrame);img1.DrawToHDC(pDC.GetSafeHdc() ,r);//ReleaseDC( &pDC );//cvReleaseCapture(&pCapture);//ReleaseDC( &pDC );//cvReleaseImage( &pFrame );CView::OnTimer(nIDEvent);}




原创粉丝点击