我是opencv及其开发的新手。我正在拍摄相机,我将其转换为avi格式的视频文件。当我尝试使用VLC播放器打开该文件时。什么都没有给我看。请在下面找到我使用的代码。任何帮助表示赞赏。(文件写入文件,但我认为它的文件格式有问题)
int main(int argc, char** argv){
VideoCapture vcap(0);
if(!vcap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
// VideoWriter video("/Users/venushka/Desktop/pre/ou.avi",vcap.get(CV_CAP_PROP_FOURCC),vcap.get(CV_CAP_PROP_FPS),
// cv::Size(vcap.get(CV_CAP_PROP_FRAME_WIDTH), vcap.get(CV_CAP_PROP_FRAME_HEIGHT)));
const int fps = 30.0;
vcap.set(CV_CAP_PROP_FPS, fps);
VideoWriter video("/Users/venushka/Desktop/pre/ou.avi", vcap.get(CV_CAP_PROP_FOURCC), fps,
cv::Size(vcap.get(CV_CAP_PROP_FRAME_WIDTH), vcap.get(CV_CAP_PROP_FRAME_HEIGHT)));
for(;;){
Mat frame;
vcap >> frame;
video.write(frame);
imshow( "Frame", frame );
char c = (char)waitKey(33);
if( c == 27 ) break;
}
return 0;
}
答案 0 :(得分:0)
CV_CAP_PROP_FPS
仅适用于视频,相机会返回0。
按如下方式手动设置您的FPS:
const int fps = 30.0;
vcap.set(CV_CAP_PROP_FPS, fps);
VideoWriter video("<path to avi>", vcap.get(CV_CAP_PROP_FOURCC), fps,
cv::Size(vcap.get(CV_CAP_PROP_FRAME_WIDTH), vcap.get(CV_CAP_PROP_FRAME_HEIGHT)));