From 2206780a9b468e5592dbedfd3db456068107ca3c Mon Sep 17 00:00:00 2001 From: Epicalert Date: Wed, 16 Jun 2021 19:03:06 +0800 Subject: [PATCH] Add error messages for camera problems --- src/cv.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cv.cpp b/src/cv.cpp index adf29b6..1047684 100644 --- a/src/cv.cpp +++ b/src/cv.cpp @@ -9,6 +9,7 @@ #include #include #include +#include cv::Ptr 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* faces) {