opencv2读取摄像头并保存为视频

opencv2读取摄像头并保存为视频

#include 
#include 
#include 
using namespace cv;
using namespace std;
int main()
{
	VideoCapture cap(0);//读取usb摄像头视频
	if(!cap.isOpened())
	{
		cout<<"Capture could not be opened successfully"<		return -1;
	}
	Size S=Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),(int)cap.get(CV_CAP_PROP_FRAME_HEIGHT));
	VideoWriter put("output.mpg",CV_FOURCC('M','P','E','G'),50,S);//输出保存为视频名为output.mpg;MPEG为对应的编码器。
	//VideoWriter put("output.avi",CV_FOURCC('M','P','E','G'),50,S);//可以将视频保存为avi格式的
	if(!put.isOpened())

{ cout<<"File could not be created for writing. Check permissions"< return -1; } namedWindow("Video"); while(char(waitKey(1))!='q'&&cap.isOpened()) { Mat frame; cap>>frame; if(frame.empty()) { cout<<"Video over"< break; } imshow("Video",frame); put< } return 0; }


opencv2读取摄像头并保存为视频_第1张图片

你可能感兴趣的:(图像处理(opencv))