在Ubuntu上使用OpenCV 2.4.1从图像创建视频 [英] Creating Video from Images with OpenCV 2.4.1 on Ubuntu
问题描述
这是我的示例程序,用于使用OpenCV从图像创建视频. 但是我的输出视频无法正常工作,并且出现错误并指出无法多路分解流" 请帮忙.
Here is my sample program for creating Video from images with OpenCV. But my output video is not working and An error occurred ans stating that "Could not demultiplex stream" Please help.
#include<cv.h>
#include<highgui.h>
#include<cvaux.h>
#include<cxcore.h>
int main()
{
//CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 25; // or 30
int frameW = 320; // 744 for firewire cameras
int frameH = 240; // 480 for firewire cameras
CvSize size;
size.width = frameW;
size.height = frameH;
CvVideoWriter *writer = cvCreateVideoWriter(
"data3.avi",
CV_FOURCC('M','J','P','G'),
fps,
size);
IplImage* img = 0;
img=cvLoadImage("IMG_0157.JPG");
for(int counter=0;counter < 3000;counter++)
{
cvWriteFrame(writer,img); // add the frame to the file
}
cvReleaseVideoWriter(&writer);
return 0;
}
推荐答案
您可以尝试使用其他FOURCC代码.其中一些不受OpenCV的正确支持,一些不受多媒体应用程序的支持.拥有既可以与OpenCV一起使用,又可以与您喜欢的视频播放器一起使用的播放器是一个反复试验的问题.
You can try a different FOURCC code. Some of them are not correctly supported by OpenCV, some by the multimedia apps. Having one that works with both OpenCV and your favourite video player is a matter of trial and error.
您可以尝试的方法:使用VLC(以防万一,不要使用它).它是那里最强大的参与者之一.
What you can try: Use VLC (in case you don't alreay use it). It is one of the most robust players out there.
如果您要做的只是将OpenCV中的一系列图像显示/处理为视频,则可以使用VideoCapture的未记录功能:加载一系列图像.
If all you want to do is to display/process a sequence of images in OpenCV as video, you can use an undocumented feature of the VideoCapture: Load a sequence of images.
该示例使用C ++,但您可以轻松地将其转换为C.
The example is in C++, but you can easily convert it to C.
// pics are a sequence of Pictures001.jpg, PicturesS002.jpg, etc
cv::VideoCapture cap("path/to/my/Pictures%03d.jpg");
cv::Mat frame;
for(;;)
{
cap >> frame;
if(frame.empty())
break;
// do some processing
}
这篇关于在Ubuntu上使用OpenCV 2.4.1从图像创建视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!