0

I've just written a first program for videocaptur and videowriter. I copied the source from the wiki and changed the only video file name, but it made error.

Here is the source from the wiki.

The opencv is 2.1 and the compiler is 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;
}

With the source, I changed 2 parts. One is for VideoCapture. (I don't have tunercard or camera.) The source is

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

and changed to

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

And the other is for VideoWriter:

   // record video

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

and changed to

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

and the part of error is:

        // add frame to recorded video

        record << frame; 

Please show me what is my mistake!

P.S. when I delete the line record << frame;, it works well. I think the error caused at the line.

And I found that even if without change, the wiki source program make same error.

Mat
  • 202,337
  • 40
  • 393
  • 406
sirupa
  • 35
  • 1
  • 8

2 Answers2

0

please make sure you opencv_ffmpegXXX.dll work right

0

The first error that i see is the file paths. You have to give them like this : C:\\Users\\....

Adrian
  • 2,028
  • 2
  • 17
  • 28