3

我正在树莓派中制作类似黑匣子的东西。

我设置了 OpenCV 2.4.3 和许多视频库。(我提到了这个网站 - Opencv 无法访问我的网络摄像头

我编译了这个示例代码。

#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cxcore.h"

int main(void){
    CvCapture* capture = cvCaptureFromCAM(0);
    cvNameWindow("video", 1);

    double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    CvSize frame_size = cvSize((int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
    CvVideoWriter* writer = cvCreateVideoWriter("out.avi", -1, fps, frame_size, 1);

    IpImage* frame;
    while(1){
        frame = cvQueryFrame(capture);
        cvShowImage("video", frame);
        if(cvWaitKey(38) == 27){
            break;
        }
    }

    cvReleaseVideoWriter(&writer);
    cvReleaseCapture(&capture);
    cvDestroyWindow("video");

    return 0;
}

此代码编译成功。

但是当我运行这个过程时,有一些错误。

OpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend doesn't support this codec acutally.) in CvVideoWriter_GStreamer::open, file /home/pi/OpenCV-2.4.3/modules/highgui/src/cap_gstreamer.cpp, line 479
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pi/OpenCV-2.4.3/modules/highgui/src/cap_gstreamer.cpp:479: error: (-210) Gstreamer Opencv backend doesn't support this codec acutally. in function CvVideoWriter_GStreamer::open

Aborted

所以,我改变了'cvCreateVideoWriter'中的编解码器部分而不是-1。我尝试了许多类型的编解码器,例如 'CV_FOURCC('M','J','P','G')' 等等..

但我无法解决这个问题。

我怎么解决这个问题?请帮我..

4

0 回答 0