title: saving an image sequence from video using opencv2
body: <p>Newbie question and yes I have spent a lot of time sifting through similar questions and Answers with no luck.</p>
  
  <p>What I am trying to do is save frames from a video file in a sequential order. I have managed to save one image using c and I cannot seem to save images after that. I have started using c++ in opencv instead of c and all I can do is view the video and not save any jpg's from it.  </p>
  
  <p>I am using opencv2.4.4a on mac if that helps. 
  below is my c example</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;opencv/cv.h&gt;
  #include &lt;opencv/highgui.h&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  int main (int argc, char** argv)
  {
  //initializing capture from file
  CvCapture * capture = cvCaptureFromAVI ("/example/example.mov");
  
  //Capturing a frame
  IplImage* img = 0;
  if(!cvGrabFrame(capture))      //capture a frame
  {
  printf)Could not grab a fram\n\7");
  exit(0);
  }
  img=cvRerieveFrame(capture);    //retrieve the captured frame
  
  //writing an image to a file
  if (!cvSaveImage("/frames/test.jpg", img))
  printf("Could not save: %s\n","test.jpg");
  
  //free resources
  cvReleaseCapture(&amp;capture);
  
  }
  </code></pre>
  
  <p>Thank you in advance</p>
  
  <p>edit to the above.</p>
  
  <p>I have added to the above code which results in an image to be saved with the test.jpg and then gets rewritten with the next frame. How do I tell opencv to not copy over the last image and rename the next frame to test_2.jpg eg, test_1.jpg, test_2.jpg and so on?</p>
  
  <pre><code>double num_frames = cvGetCaptureProperty (capture, CV_CAP_PROP_FRAME_COUNT);
  
  for (int i = 0; i &lt; (int)num_frames; i++)
  {
  img = cvQueryFrame(capture);
  cvSaveImage("frames/test.jpg", img);
  }
  
  cvReleaseCapture(&amp;capture);
  }
  </code></pre>