视频读取速度太快

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);

	}




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

superdont

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值