【问题标题】:opcv videowriter, i don't know why it does'nt workopencv videowriter,我不知道为什么它不起作用
【发布时间】:2014-05-13 17:31:01
【问题描述】:

我刚刚为 videocaptur 和 videowriter 编写了第一个程序。我从 wiki 复制了源代码并更改了唯一的视频文件名,但它出错了。

这是来自维基的来源。

opencv是2.1,编译器是visual c++ 2008 express。

#include "cv.h"
#include "highgui.h"

using namespace cv;

int main(int, char**)

{

        VideoCapture capture(1); // open the default camera

        if( !capture.isOpened() )  {

                printf("Camera failed to open!\n");

                return -1;
        }

        Mat frame;

        capture >> frame; // get first frame for size

        // record video

        VideoWriter record("RobotVideo.avi", CV_FOURCC('D','I','V','X'), 30, frame.size(), true);

        if( !record.isOpened() ) {

                printf("VideoWriter failed to open!\n");

                return -1;

        }

        namedWindow("video",1);

        for(;;)

        {
                // get a new frame from camera

                capture >> frame; 

                // show frame on screen

                imshow("video", frame); 

                // add frame to recorded video

                record << frame; 

                if(waitKey(30) >= 0) break;

        }

        // the camera will be deinitialized automatically in VideoCapture destructor
        // the recorded video will be closed automatically in the VideoWriter destructor

        return 0;
}

使用源代码,我更改了 2 个部分。一种是用于 VideoCapture。 (我没有调谐卡或相机。)来源是

    VideoCapture capture(1); // open the default camera

改成

 VideoCapture capture("C:/Users/Public/Videos/Sample Videos/WildlifeTest.wmv"); 

另一个是给VideoWriter的:

   // record video

    VideoWriter record("RobotVideo.avi", CV_FOURCC('D','I','V','X'), 30, frame.size(), true);

改成

  VideoWriter record("C:/Users/Public/Videos/Sample Videos/WildlifeRec.wmv",
                      CV_FOURCC('W','M','V','1'), 30,frame.size(), true);

错误的部分是:

        // add frame to recorded video

        record << frame; 

请告诉我我的错误是什么!

附: 当我删除record &lt;&lt; frame; 行时,它运行良好。我认为是在该行引起的错误。

我发现即使不做改动,wiki源程序也会出现同样的错误。

【问题讨论】:

    标签: opencv video-capture


    【解决方案1】:

    我看到的第一个错误是文件路径。你必须像这样给他们:C:\\Users\\....

    【讨论】:

      【解决方案2】:

      请确保您的 opencv_ffmpegXXX.dll 工作正常

      【讨论】:

        猜你喜欢
        • 2015-02-01
        • 2016-08-25
        • 2013-11-27
        • 1970-01-01
        • 2012-04-06
        • 2020-09-19
        • 2014-01-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多