1

我正在关注 OpenCV 书籍的教程,但以下代码不起作用:

#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;

int main() {
    string arg1 = "new.mov";
    string arg2 = "mov.mov";
    CvCapture* capture = 0;
    capture = cvCreateFileCapture(arg1.c_str());
    if(!capture){
        return -1;
    }
    IplImage *bgr_frame=cvQueryFrame(capture);
    double fps = cvGetCaptureProperty (
            capture,
            CV_CAP_PROP_FPS
    );
    CvSize size = cvSize(
            (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
            (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH)
    );
    CvVideoWriter* writer = cvCreateVideoWriter(
        arg2.c_str(),
        CV_FOURCC('N', 'T', 'S', 'C'),
        fps,
        size
    );
    IplImage* logpolar_frame = cvCreateImage(
            size,
            IPL_DEPTH_8U,
            3
    );
    while((bgr_frame=cvQueryFrame(capture)) != NULL){
        cvLogPolar(
                bgr_frame, logpolar_frame,
                cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
                40,
                CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS
                );
                cvWriteFrame(writer, logpolar_frame);
    }
    cvReleaseVideoWriter(&writer);
    cvReleaseImage(&logpolar_frame);
    cvReleaseCapture(&capture);
    return 0;
}

当我运行代码时它不会给我一个错误 - 而是程序输出到控制台:

WARNING: Could not create empty movie file container.

接下来是 100 左右行:

Didn't successfully update movie file.

这个错误(或任何它的名字)是什么意思,是什么原因造成的?

我不知道这是否有帮助,但它曾经给我一个关于编解码器的错误(在书中是 MJPG),所以我CV_FOURCC('M', 'J', 'P', 'G')改为CV_FOURCC('N', 'T', 'S', 'C').

4

3 回答 3

2

NTSC 不是有效的编解码器fourcc,因此没有创建视频写入器

于 2012-06-18T16:39:31.023 回答
2

尝试更改CV_FOURCC('N', 'T', 'S', 'C')CV_FOURCC('D', 'I', 'V', 'X'). 这是给你的手册

可能的编解码器:

CV_FOURCC('P','I','M','1')    = MPEG-1 codec
CV_FOURCC('M','J','P','G')    = motion-jpeg codec (does not work well)
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
于 2012-06-18T16:46:30.190 回答
1

来寻找相同消息的解决方案。就我而言,我使用 Mac/OSX,并且我确实使用了 CV_FOURCC('M', 'J', 'P', 'G')。结果是,当输出文件以“.mp4”结尾并使用“.avi”时,它失败了。

于 2012-07-27T10:15:43.953 回答