Ignore empty frames to prevent crashes

This commit is contained in:
Epicalert 2021-06-12 17:32:41 +08:00
parent 735e27ac53
commit 325ff2ce7d
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD

View file

@ -26,6 +26,8 @@ void initCV() {
facemark->loadModel (resolvePath("cvdata/lbfmodel.yaml")); facemark->loadModel (resolvePath("cvdata/lbfmodel.yaml"));
vid = cv::VideoCapture (0); vid = cv::VideoCapture (0);
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) {
@ -56,6 +58,8 @@ void dnnFaceDetect(cv::Mat inFrame, std::vector<cv::Rect>* faces) {
void cvFrame() { void cvFrame() {
vid.read(frame); vid.read(frame);
if(frame.empty()) return;
cv::cvtColor (frame, gray, cv::COLOR_BGR2GRAY); cv::cvtColor (frame, gray, cv::COLOR_BGR2GRAY);
std::vector<cv::Rect> faces; std::vector<cv::Rect> faces;
@ -157,6 +161,8 @@ void cvFrame() {
} }
void cvShowFrame() { void cvShowFrame() {
if(frame.empty()) return;
cv::imshow("Video Input", frame); cv::imshow("Video Input", frame);
cv::waitKey(1); cv::waitKey(1);
} }