Opencv驱动摄像头,此段代码只能驱动电脑自带摄像头,目前没有分析出为何不能驱动另外连接的相机!
#include<iostream>
#include<opencv2\core.hpp>
#include<opencv2\highgui.hpp>
#include<opencv2\imgproc.hpp>
#include<opencv2\imgcodecs.hpp>
using namespace cv;
using namespace std;//显示图像
int main(int argc, char **argv)
{窗口名称//string windowName = "helloworld";图像名称//string imgFile = "D:/220502.jpg";读入图像//Mat image = cv::imread(imgFile);//if (!image.data)//{// cout << "无法打开图像文件!" << std::endl;// waitKey(0);// return -1;//}创建一个新窗口//namedWindow(windowName, WINDOW_AUTOSIZE);将图像显示在新建的窗口中//imshow(windowName, image);等待,直到用户按任意键退出VideoCapture video(0);//VideoCapture video('rtsp://192.168.1.10/1');if (!video.isOpened()){cout << "打开失败!" << endl;system("pause");return 0;}while (1){Mat frame;video >> frame;if (frame.empty()){break;}imshow("video", frame);waitKey();}waitKey(0);return 0;}