如何在C++中从摄像头流式传输图像/数据

4

我在我的Windows 7电脑上插了一个USB摄像头,现在正在尝试编写一个程序来从摄像头中流传图像。

我已经获取了这个摄像头的VID和PID,但不知道如何继续。请帮忙指导。

谢谢。


你考虑过使用DirectShow吗?我在这里写了一篇关于它的文章(http://stackoverflow.com/questions/7859442/grab-video-stream-from-firewire/7865752#7865752)。也许它会有用。 - baderman
1个回答

5
如果您能使用OpenCV,这里有一个非常好的例子:点击这里
 #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;
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接