opencv获取所有摄像头信息

 #include <opencv2/opencv.hpp>
#include <iostream>
#include <thread>

using namespace cv;
using namespace std;

void getCameraInfo(int cameraId) {
    VideoCapture cap(cameraId);
    if (cap.isOpened()) {
        cout << "Camera " << cameraId << " information:" << endl;
        cout << " - Width: " << cap.get(CAP_PROP_FRAME_WIDTH) << endl;
        cout << " - Height: " << cap.get(CAP_PROP_FRAME_HEIGHT) << endl;
        cout << " - FPS: " << cap.get(CAP_PROP_FPS) << endl;
        cout << " - FourCC: " << cap.get(CAP_PROP_FOURCC) << endl;
        cap.release();
    }
}

int main()
{
    // 获取系统上的摄像机数量
    int cameraCount = cv::VideoCapture::getNumberOfCameras();

    // 创建线程数组,每个线程获取一个摄像机的信息
    thread threads[cameraCount];
    for (int i = 0; i < cameraCount; i++) {
        threads[i] = thread(getCameraInfo, i);
    }

    // 等待所有线程完成
    for (int i = 0; i < cameraCount; i++) {
        threads[i].join();
    }

    return 0;
}

  

posted @ 2023-04-19 15:17  NAVYSUMMER  阅读(1279)  评论(0)    收藏  举报
交流群 编程书籍