【发布时间】:2013-09-03 17:27:34
【问题描述】:
我正在尝试使用以下代码使用 openCV 2.4.6.1 修改和编写一些视频:
cv::VideoCapture capture( video_filename );
// Check if the capture object successfully initialized
if ( !capture.isOpened() )
{
printf( "Failed to load video, exiting.\n" );
return -1;
}
cv::Mat frame, cropped_img;
cv::Rect ROI( OFFSET_X, OFFSET_Y, WIDTH, HEIGHT );
int fourcc = static_cast<int>(capture.get(CV_CAP_PROP_FOURCC));
double fps = 30;
cv::Size frame_size( RADIUS, (int) 2*PI*RADIUS );
video_filename = "test.avi";
cv::VideoWriter writer( video_filename, fourcc, fps, frame_size );
if ( !writer.isOpened() && save )
{
printf("Failed to initialize video writer, unable to save video!\n");
}
while(true)
{
if ( !capture.read(frame) )
{
printf("Failed to read next frame, exiting.\n");
break;
}
// select the region of interest in the frame
cropped_img = frame( ROI );
// display the image and wait
imshow("cropped", cropped_img);
// if we are saving video, write the unwrapped image
if (save)
{
writer.write( cropped_img );
}
char key = cv::waitKey(30);
当我尝试使用 VLC 运行输出视频“test.avi”时,我收到以下错误:avidemux 错误:没有为轨道 0 设置关键帧。我使用的是 Ubuntu 13.04,我尝试使用编码的视频使用 MPEG-4 和 libx264。我认为修复应该很简单,但找不到任何指导。实际代码可在https://github.com/benselby/robot_nav/tree/master/video_unwrap 获得。提前致谢!
【问题讨论】:
-
你有没有弄清楚问题是什么?我遇到了同样的问题。
-
我现在也在尝试追查这个问题。如果我找到答案,我会回来报告。
-
在我的情况下,问题是:1)大小不匹配:Mat 有
height行和width列,但作者采用了(width,height)的大小,即按其他顺序和2 ) 灰度图像:我传递的 Mat 是width x height x 1,显然它想要width x height x 3(在 python 下)。这是 OpenCV 2.4.8。