vs+win10+opencv 读取外接usb相机

时间:2024-03-24 13:58:28

做课题需要外接USB相机,尝试用opencv调用再进行相关的处理;

推荐使用opencv自带的CV_CAP_DSHOW来打开外置相机;

代码:


#include"cv.h"
#include<opencv2/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include"iostream"
using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
	VideoCapture cap(CV_CAP_DSHOW + 1);
	Mat frame;
	while (1)
	{
		cap >> frame;
		imshow("dd", frame);
		waitKey(30);
	}
	
	return 0;
}

程序运行截图:

vs2017+win10+opencv 读取外接usb相机