2012-05-11 43 views
4

我的电脑中安装了USB摄像头(使用Windows 7),我试图创建一个程序来传输摄像头中的图像。如何在C++中以摄像头流式传输图像/数据

我该如何去做这件事?我已经获得了相机的VID和PID,但对此不了解更多。请帮忙。

感谢

+0

你因子评分关于使用DirectShow?我已经写了关于它[这里](http://stackoverflow.com/questions/7859442/grab-video-stream-from-firewire/7865752#7865752)。也许它会很有用。 – baderman

回答

5

如果你可以使用OpenCV的,有一个非常好的例子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; 
} 
相关问题