【发布时间】:2012-05-11 12:34:37
【问题描述】:
我的 PC 中插入了一个 USB 摄像头(使用 Windows 7),我正在尝试创建一个程序来从摄像头流式传输图像。
我该怎么做呢?我有摄像机的 VID 和 PID,但对它一无所知。请帮忙。
谢谢
【问题讨论】:
-
您对使用 DirectShow 有过犹豫吗?我已经写了here。也许会有用。
标签: c++ image camera streaming
我的 PC 中插入了一个 USB 摄像头(使用 Windows 7),我正在尝试创建一个程序来从摄像头流式传输图像。
我该怎么做呢?我有摄像机的 VID 和 PID,但对它一无所知。请帮忙。
谢谢
【问题讨论】:
标签: c++ image camera streaming
如果你可以使用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;
}
【讨论】: