Add error messages for camera problems

This commit is contained in:
Epicalert 2021-06-16 19:03:06 +08:00
parent 5bea68564f
commit 2206780a9b
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD

View file

@ -9,6 +9,7 @@
#include <cv.hpp>
#include <eye.hpp>
#include <modelpart.hpp>
#include <error.hpp>
cv::Ptr<cv::face::Facemark> facemark;
cv::CascadeClassifier haarFaceDetector;
@ -38,12 +39,16 @@ void initCV() {
facemark = cv::face::FacemarkLBF::create();
facemark->loadModel (resolvePath("cvdata/lbfmodel.yaml"));
bool cameraOpened = false; // true if *any* camera could be opened
bool cameraAccepted = false; // true if we have accepted a camera
// 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;
cameraOpened = true;
// check if camera is giving solid colored frames
cv::Mat testFrame;
@ -53,10 +58,24 @@ void initCV() {
std::cout << "Camera " << i << " feed blank!" << std::endl;
} else {
std::cout << "Using camera " << i << std::endl;
cameraAccepted = true;
break;
}
}
}
// show errors if no camera found
if (!cameraAccepted) {
if (cameraOpened) {
showError("A camera was found, but the feed is blank. Check if your camera is "
"functioning properly and try again.",
"Camera error", true);
} else {
showError("No cameras were found. Check if your camera is plugged in and "
"detected by your computer.",
"No camera found", true);
}
}
}
void dnnFaceDetect(cv::Mat inFrame, std::vector<cv::Rect>* faces) {