写作OpenCV的AVI文件 [英] Writing AVI files in OpenCV

查看:157
本文介绍了写作OpenCV的AVI文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有上给出的了解OpenCV的净和code为例,Orielly。

多次尝试后,out.avi文件写入0字节。
我不知道我在哪里出了错。

以下是code我用...

  INT主(INT ARGC,CHAR *的argv []){
    CvCapture *输入= cvCaptureFromFile(的argv [1]);
    * IplImage的图像= cvRetrieveFrame(输入);    如果(!图片){
        的printf(无法读取输入);
        返回0;
    }
    CvSize imgSize;
    imgSize.width =图像 - >宽度;
    imgSize.height =图像 - >高度;    双FPS = cvGetCaptureProperty(
            输入,
            CV_CAP_PROP_FPS
            );    CvVideoWriter *作家= cvCreateVideoWriter(
            out.avi
            CV_FOURCC(M,J,P,G),
            FPS,
            imgSize
            );
    *的IplImage colourImage;
    //保留处理帧...
    为(;;){        //从输入视频的帧。
        colourImage = cvQueryFrame(输入);
        cvWriteFrame(作家,colourImage);    }    cvReleaseVideoWriter(安培;作家);
    cvReleaseCapture(安培;输入);}


解决方案

我敢打赌,cvCreateVideoWriter返回NULL。只是通过它一步,看它是否是真的。在这种情况下,问题可能是与CV_FOURCC(..)的犯规找到codeC和强制返回0;

您可以尝试使用-1,而不是CV_FOURCC。有会是在运行时提示为你选择合适的codeC

There example on the net and code given in Learn OpenCv,Orielly.

After many attempts the out.avi file is written with 0 bytes. I wonder where i went wrong.

The following are the code i used...

int main(int argc, char* argv[]) {
    CvCapture* input = cvCaptureFromFile(argv[1]);
    IplImage* image = cvRetrieveFrame(input);

    if (!image) {
        printf("Unable to read input");
        return 0;
    }


    CvSize imgSize;
    imgSize.width = image->width;
    imgSize.height = image->height;



    double fps = cvGetCaptureProperty(
            input,
            CV_CAP_PROP_FPS
            );

    CvVideoWriter *writer = cvCreateVideoWriter(
            "out.avi",
            CV_FOURCC('M', 'J', 'P', 'G'),
            fps,
            imgSize
            );


    IplImage* colourImage;
    //Keep processing frames...
    for (;;) {

        //Get a frame from the input video.
        colourImage = cvQueryFrame(input);
        cvWriteFrame(writer, colourImage);

    }

    cvReleaseVideoWriter(&writer);
    cvReleaseCapture(&input);

}

解决方案

My bet is that cvCreateVideoWriter returns NULL. Just step through it to see if it's true. In that case, the problem is probably with CV_FOURCC(..) which doesnt find the codec and force a return 0;

you can try using -1 instead of CV_FOURCC. There is gonna be a prompt during runtime for you to chose the appropriate codec

这篇关于写作OpenCV的AVI文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆