4

I have a USB camera pluged in my PC (using windows 7) and I'm trying to create a program to stream images from the camera.

How do I go about doing this? I've got the VID and PID of the camera, but don't know anything more about it. Please help.

Thanks

Danny
  • 9,199
  • 16
  • 53
  • 75
  • Have you tought about using DirectShow? I've wrote about it [here](http://stackoverflow.com/questions/7859442/grab-video-stream-from-firewire/7865752#7865752). Maybe it'll be useful. – baderman May 11 '12 at 15:31

1 Answers1

5

If you can use OpenCV, there is a very nice example here

 #include "cv.h" 
 #include "highgui.h" 
 #include <stdio.h>  
 // A Simple Camera Capture Framework 
 int main() {
   CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
   if ( !capture ) {
     fprintf( stderr, "ERROR: capture is NULL \n" );
     getchar();
     return -1;
   }
   // Create a window in which the captured images will be presented
   cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
   // Show the image captured from the camera in the window and repeat
   while ( 1 ) {
     // Get one frame
     IplImage* frame = cvQueryFrame( capture );
     if ( !frame ) {
       fprintf( stderr, "ERROR: frame is null...\n" );
       getchar();
       break;
     }
     cvShowImage( "mywindow", frame );
     // Do not release the frame!
     //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
     //remove higher bits using AND operator
     if ( (cvWaitKey(10) & 255) == 27 ) break;
   }
   // Release the capture device housekeeping
   cvReleaseCapture( &capture );
   cvDestroyWindow( "mywindow" );
   return 0;
 }
Alessandro Teruzzi
  • 3,918
  • 1
  • 27
  • 41