USB相机便宜,使用起来方便,而opencv也包含了读取USB相机视频数据的API函数。在windows xp中,该API函数是利用windows的VFW模块来实现的。下面,我给出
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
CvCapture *cap = cvCreateCameraCapture(0);//初始化相机捕获的指针
if (!cap)
{
cout<<"create camera capture error..."<<endl;
system("pause");
exit(-1);
}
cvNamedWindow("img");
相应的参考代码:
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
CvCapture *cap = cvCreateCameraCapture(0);//初始化相机捕获的指针
if (!cap)
{
cout<<"create camera capture error..."<<endl;
system("pause");
exit(-1);
}
cvNamedWindow("img");