Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you just need to change the name, so it does not overwrite the previous with the currnt frame.

   int counter = 0; // NEW !
   for(;;){ //forever
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          String name = format("img%04d.png", counter++) // NEW !
          imwrite(name, frame); 
          // btw, you sloppily 
          // a: swapped img & name above,
          // b: also, c++ does use "" for strings, your original code would *never* compile ...
          if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC 
    }

you just need to change the name, so it does not overwrite the previous with the currnt current frame.

   int counter = 0; // NEW !
   for(;;){ //forever
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          String name = format("img%04d.png", counter++) // NEW !
          imwrite(name, frame); 
          // btw, you sloppily 
          // a: swapped img & name above,
          // b: also, c++ does use "" for strings, your original code would *never* compile ...
          if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC 
    }

you just need to change the name, so it does not overwrite the previous with the current frame.

   int counter = 0; // NEW !
   for(;;){ //forever
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          String name = format("img%04d.png", counter++) counter++); // NEW !
          imwrite(name, frame); 
          // btw, you sloppily 
          // a: swapped img & name above,
          // b: also, c++ does use "" for strings, your original code would *never* compile ...
          if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC 
    }