opencv4.0 摄像头视频读取与保存(vs2017)

#include
#include
#include 
using namespace cv;
using namespace std;
int main()
{
	VideoCapture capture;
	capture.open("E:/openvinoR1/test_image_video/capture06.MP4");

	if (!capture.isOpened())
	{
		printf("can not open capture...\n");
		return -1;
	}

	Mat frame;

	capture.read(frame);
	if (frame.empty()) return -1;

	Size size = Size(capture.get(CAP_PROP_FRAME_WIDTH), capture.get(CAP_PROP_FRAME_HEIGHT));//CAP_OPENCV_MJPEG
	VideoWriter writer;
	writer.open("E:/openvinoR1/test_image_video/capture06c12.MP4", writer.fourcc('M', 'P', '4', '2'), 30, size, true);//CAP_OPENCV_MJPEG

	namedWindow("capture");
	while (1)
	{
		capture.read(frame);
		if (frame.empty()) break;
		flip(frame, frame, 1);//左右镜像翻转
		writer.write(frame);
		imshow("capture", frame);
		waitKey(30);

		if (waitKey(5) == 27)//按ESC键退出while循环
		{
			break;
		}	
	}
	capture.release();
	waitKey(0);
	return 0;
}

 

你可能感兴趣的:(#,opencv)