本文共 843 字,大约阅读时间需要 2 分钟。
这有如何安装OpenCV的教程:
下面代码转自:http://blog.csdn.net/swordll80/archive/2007/07/25/1708106.aspx
#include <stdafx.h>
#pragma warning(disable : 4996) #include <cxcore.h> #include <highgui.h> void main(int argc, char *argv[]) { CvCapture* capture = 0;//视频流捕获 if(argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM(argc == 2 ? argv[1][0] - '0' : 0);//从摄像头获得视频流 else if( argc == 2 ) capture = cvCaptureFromAVI(argv[1]);//从文件获得视频流 if(!capture) return; IplImage *current_frame_rgb = cvCreateImage(cvSize(320, 240), IPL_DEPTH_16U, 3); cvNamedWindow("Window 0", 0); while(capture) { current_frame_rgb = cvQueryFrame(capture);//获得一帧图象 cvShowImage("Window 0",current_frame_rgb); if(cvWaitKey(1)==27)//等待ESC键 break; } cvDestroyAllWindows(); }