1. 程式人生 > >OpenCV學習筆記_呼叫攝像頭錄製視訊(無聲音)

OpenCV學習筆記_呼叫攝像頭錄製視訊(無聲音)

#include <cv.h>
#include <highgui.h>

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