我是新手,开始在 ubuntu 10.4 上使用 OpenCV。我正在尝试从相机捕获视频并将该视频写入 avi 文件,代码如下:
#include "opencv2/opencv.hpp"
#include <iostream>
#include <vector>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("cam1",CV_WINDOW_AUTOSIZE);
Mat frame;
VideoWriter outputVideo("lalala.avi", CV_FOURCC('D','I','V','X') , 30, Size(720, 480) , true); // or frame.size()
outputVideo.open("lalala.avi", CV_FOURCC('D','I','V','X') , 30, Size(720, 480), true) ; // or frame.size()
if( !outputVideo.isOpened() ) {
printf("VideoWriter failed to open!\n");
}
for(;;)
{
cap >> frame; // get a new frame from camera
imshow("cam1", frame);
outputVideo.write(frame); // or outputVideo << frame;
if(waitKey(30) >= 0) break;
}
return 0;
}
最佳答案
要么您没有写入文件的权限,要么您使用的编解码器未包含在您的 openCV 构建中。
要下载并安装完整的 opencv(包括 ffmpeg),请参阅 http://opencv.willowgarage.com/wiki/InstallGuide%20%3A%20Debian
https://stackoverflow.com/questions/9666709/