Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if you open a new videowriter per image, it's no big wonder, it ends up with 0 seconds...

also, please make it a habit, to check resources and return values whenever possible !

 VideoWriter video("out.avi", CV_FOURCC('M','J','P','G'), 30, Size(640, 480), false);
 if (!video.isOpened())
 {
       .... fail
 }
 for(int i = 0; i < 30; i++)
 {
    char left[1024] = "";
    sprintf(left, "left640x480_%d.bmp", i);

    // please do not preallocate it, it will be overwritten anyway, and your 
    // original code had width & height in reverse !
    Mat image = imread(left, 0); 
   if (image.empty())
   {
          ... fail !
   }
    bool ok = video.write(image); // no copy needed, don't vodoo !
   if (! ok)
   {
          ... fail !
   }

    imshow( "Frame", image );
    char c = (char)waitKey(33);
    if( c == 27 )
        break;

if you open a new videowriter per image, it's no big wonder, it ends up with 0 seconds...

also, please make it a habit, to check resources and return values whenever possible !

 VideoWriter video("out.avi", CV_FOURCC('M','J','P','G'), 30, Size(640, 480), false);
 if (!video.isOpened())
 {
       .... fail
 }
 for(int i = 0; i < 30; i++)
 {
    char left[1024] = "";
    sprintf(left, "left640x480_%d.bmp", i);

    // please do not preallocate it, it will be overwritten anyway, and your 
    // original code had width & height in reverse !
    Mat image = imread(left, 0); 
   if (image.empty())
   {
          ... fail !
   }
    bool ok = video.write(image); // no copy needed, don't vodoo !
   if (! ok)
   {
          ... fail !
   }

    imshow( "Frame", image );
    char c = (char)waitKey(33);
    if( c == 27 )
        break;