void QtOpenCVZedDemo::enumCameras() { ui->comboBox_cameras->clear(); if(mCapture.isOpened()) mCapture.release(); cv::VideoCapture temp_camera; int maxTested = 10; bool found = false; for (int i = 0; i < maxTested; i++) { cv::VideoCapture temp_camera(i); bool res = temp_camera.isOpened(); temp_camera.release(); if (res) { found = true; ui->comboBox_cameras->addItem( tr("%1").arg(i) ); } } if( found ) ui->comboBox_cameras->setCurrentIndex(0); else ui->comboBox_cameras->setCurrentIndex(-1); }
//Get the number of cameras available int countCameras(){ VideoCapture temp_camera; int maxTested = 10; for (int i = 0; i < maxTested; i++){ VideoCapture temp_camera(i); bool res = (!temp_camera.isOpened()); temp_camera.release(); if (res){ return i; } } return maxTested; }