OpenCV读取视频流操作

VS2012 + OpenCV2.4.4读取视频流操作:

见代码注释:

#include 
#include 
int main()
{
	//cv::VideoCapture capture("D:/Development/OpenCV/images/bike.avi") ;
	cv::VideoCapture capture ;
	//capture.open("D:/Development/OpenCV/images/bike.avi") ;
	capture.open(0) ;//打开默认camera设备(摄像头)
	if(!capture.isOpened())
	{
		std::cout << " NO " << std::endl ;
	}
	//得到帧率和总帧数 ,指定相应参数获取相应值
	double rate = capture.get(CV_CAP_PROP_FPS) ;
	long   ctnum = static_cast (capture.get(CV_CAP_PROP_FRAME_COUNT) ) ;
	std::cout << "rate = " << rate << std::endl ;
	std::cout << "Frame num = " << ctnum << std::endl ;
	
	bool stop = false ;
	cv::Mat frame ;
	cv::namedWindow("Extracted Frame") ;
	int delay = 1000 / rate ;

	//移动到指定的帧位置 ,相应Flag,相应的移动方式
	//capture.set(CV_CAP_PROP_POS_FRAMES , 50.0) ;
	//capture.set(CV_CAP_PROP_POS_MSEC , 3000) ;
	//capture.set(CV_CAP_PROP_POS_AVI_RATIO , 0.2) ;
	while (!stop)
	{
		if(!capture.read(frame))//帧读完时退出
			break ;

		cv::imshow("Extracted Frame" , frame) ;
 		if(cv::waitKey(10) >=0 )//当按下键盘键时退出,不是实时设备用cv::waitKey(delay)
 			stop =true ;
	}
	capture.release() ;
	return 0 ;
}


你可能感兴趣的:(OpenCV)