使用最佳库从c ++快速捕获网络摄像头中的单个图像的最佳方法是什么?
编辑:
尽管常见问题示例展示了如何捕获帧流,但我将其变形以实现我需要的功能。谢谢。
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
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) & 255) == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
return 0;
}
答案 0 :(得分:3)
OpenCV具有C和C ++ API,是跨平台的,并且非常易于使用。第26-27页的Learning OpenCV中有一个示例,其中包括从网络摄像头捕获单个帧。 OpenCV FAQ中还有一个例子: http://opencv.willowgarage.com/wiki/CameraCapture