Look for usable camera instead of using default

This commit is contained in:
Epicalert 2021-06-13 22:52:57 +08:00
parent 05a4079418
commit ed5b1c26e0
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD

View file

@ -25,9 +25,16 @@ void initCV() {
facemark = cv::face::FacemarkLBF::create(); facemark = cv::face::FacemarkLBF::create();
facemark->loadModel (resolvePath("cvdata/lbfmodel.yaml")); facemark->loadModel (resolvePath("cvdata/lbfmodel.yaml"));
vid = cv::VideoCapture (0); // cycle through all available cameras until we find one we can open
std::cout << "Looking for an open camera..." << std::endl;
for (int i = 0; i < 127; i++) {
vid = cv::VideoCapture (i);
if (vid.isOpened()) {
std::cout << "Camera " << i << " opened" << std::endl;
break;
}
if(!vid.isOpened()) {std::cout << "Camera not opened!" << std::endl;} }
} }
void dnnFaceDetect(cv::Mat inFrame, std::vector<cv::Rect>* faces) { void dnnFaceDetect(cv::Mat inFrame, std::vector<cv::Rect>* faces) {