OpenCV学习笔记_调用摄像头录制视频(无声音)

#include 
#include 

using namespace std;

int main(void){
	cvNamedWindow("Camera", CV_WINDOW_AUTOSIZE);
	//初始化从摄像头中获取视频, 当只有一个摄像头时,参数为0
	CvCapture* capture = cvCreateCameraCapture(0);
	//设置视频帧数
	double fps = 30;
	//创建视频写入器
	CvVideoWriter* cvwriter = cvCreateVideoWriter("D:\\test.MJPG", CV_FOURCC('M', 'J', 'P', 'G'), fps, cvSize(640, 480));
	while (1){
		IplImage* image = cvQueryFrame(capture);
		cvShowImage("Camera", image);
		//写入帧
		cvWriteFrame(cvwriter, image);
		char c = cvWaitKey(1000 / fps);
		if (c == 27){
			cvReleaseCapture(&capture);
			break;
		}
	}
	cvReleaseVideoWriter(&cvwriter);
	cvDestroyWindow("Camera");

	return 0;
}

你可能感兴趣的:(OpenCV学习)