使用openCV读取摄像头或者视频非常方便,废话不多说,下面直接把源代码贴出来。
#include <stdio.h> #include <highgui.h> #include <cv.h> int main(int argc, char * argv[]) { IplImage* frame = NULL; cvNamedWindow("vedio"); //CvCapture* capture = cvCreateFileCapture("E:\\Videos\\shouji\\MOV0061A.avi"); CvCapture* capture = cvCreateCameraCapture(1); assert(NULL!=capture); while(1) { frame = cvQueryFrame(capture); if(!frame) { break; } cvShowImage("vedio",frame); if(27==cvWaitKey(33)) { break; } } cvReleaseCapture(&capture); cvDestroyWindow("vedio"); return 0; }