本人用的是台式机调试,所用用的摄像头也是普通的USB口的摄像头
开发环境:VS2010+opencv2.2.0
具体源码如下所示:
#include "stdafx.h"
#include <stdio.h>
#include <cxcore.h>
#include <cvaux.h>
#include <highgui.h>
#include <cv.h>
int main( int argc, char** argv )
{
//声明IplImage指针
IplImage* pFrame = NULL;
CvCapture* pCapture = NULL;
cvNamedWindow("video", 1);
cvMoveWindow("video", 30, 0); //设定窗口的位置
if( argc > 2 )
{
fprintf(stderr, "Usage: bkgrd [video_file_name]\n");
return -1;
}
//打开摄像头
if (argc ==1)
if( !(pCapture = cvCaptureFromCAM(-1)))
{
fprintf(stderr, "Can not open camera.\n");
return -2;
}
//打开视频文件
if(argc == 2)
if( !(pCapture = cvCaptureFromFile(argv[1])))
{
fprintf(stderr, "Can not open video file %s\n", argv[1]);
return -2;
}
//逐帧读取视频
while(pFrame = cvQueryFrame( pCapture ))
{
cvShowImage("video", pFrame);
if( cvWaitKey(2) >= 0 )
break;
}
//销毁窗口
cvDestroyWindow("video");
return 0;
}