我主要是用Visual Studio 2013 使用C++來開發
...
CvCapture * capture;
IplImage * frame;
capture = cvCaptureFromCAM(0);
cvNamedWindow("WebCam");
//先要一次,取得相關設定
frame = cvQueryFrame(capture);
int frameH = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frameW = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
CvSize sizeFrame = cvSize(frameH, frameW);
int fourcc = CV_FOURCC('M', 'J', 'P', 'G');
CvVideoWriter * writer = NULL;
writer = cvCreateVideoWriter("Camera.avi", fourcc, 25.0, sizeFrame);
//做一個無窮迴圈
while (true){
frame = cvQueryFrame(capture);
cvWriteFrame(writer, frame);
cvShowImage("WebCam", frame);
if (cvWaitKey(1) >= 0){
break;
}
}
cvReleaseCapture(&capture);
cvReleaseVideoWriter(&writer);
cvDestroyWindow("Webcam");
...
我發現是會產檔沒錯,但是都只有5.XX KB。
我發現上面的Code比較像是C語言的。
C++的Code網路上有找到,是可以跑得,如下:
...
cv::VideoCapture capture(0);
if (!capture.isOpened()){
return -1;
}
cv::Size videoSize = cv::Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH), (int)capture.get(CV_CAP_PROP_FRAME_HEIGHT));
cv::VideoWriter writer;
writer.open("VideoTest.avi", CV_FOURCC('M', 'J', 'P', 'G'), 30, videoSize);
cv::namedWindow("show image", 0);
while (true){
cv::Mat frame;
capture >> frame;
if (!frame.empty()){
writer.write(frame);
imshow("show image", frame);
if (cv::waitKey(33) == 27){
break;
}
}
}
...
詢問一下各位前輩,是否只能改寫成C++的版本??
還是說缺少什麼元件?