title: Capture single image from webcam
body: <p>What would be the best way using the best library to quickly capture a single image from a webcam with c++?
  EDIT:<br>
  Although the faq example showed how to capture a stream of frames, I morphed it a little to do what I need. Thank you.</p>
  
  <pre><code>#include "cv.h"  
  #include "highgui.h"  
  #include &lt;stdio.h&gt;
  int main() {  
      CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);  
      if(!capture){  
          fprintf(stderr, "ERROR: capture is NULL \n");  
          getchar();  
          return -1;  
      }  
      cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);  
      IplImage* frame = cvQueryFrame(capture);  
      if(!frame) {  
          fprintf(stderr,"ERROR: frame is null.. \n");  
          getchar();        
      }  
      while(1) {  
          cvShowImage("mywindow", frame);  
          if((cvWaitKey(10) &amp; 255) == 27) break;  
      }  
      cvReleaseCapture(&amp;capture);  
      cvDestroyWindow("mywindow");  
      return 0;  
  }  
  </code></pre>