原创
Opencv打开摄像头例子
2010-4-21 11:45
3884
2
2
分类:
软件与OS
#include "stdafx.h"
#include "highgui.h"
#include "cxcore.h"
int _tmain(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 0;
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();
}
文章评论(0条评论)
登录后参与讨论