From 57ad5cd47a32e0b00b2fa18d91c063a68b98ee50 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Fri, 12 Nov 2021 19:08:21 +0800 Subject: [PATCH] Fix crash when eye roi outside of view --- TODO.md | 1 - src/cv.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index f77c993..d5e5040 100644 --- a/TODO.md +++ b/TODO.md @@ -9,7 +9,6 @@ - model copyright and authors ## Bugs -- crash when eye goes outside of roi - incorrect appdata location on Windows # Whenever diff --git a/src/cv.cpp b/src/cv.cpp index 09f345b..099e098 100644 --- a/src/cv.cpp +++ b/src/cv.cpp @@ -170,13 +170,20 @@ void cvFrame() { cv::rectangle(frame, eyeRect, cv::Scalar(255, 255, 255)); cv::Mat eyeROI; + glm::vec2 eyeVector(0,0); + + // prevent assertion failed when eye is partly outside of image + if(eyeRect.x < 0 || eyeRect.x >= gray.cols || eyeRect.y < 0 || eyeRect.y >= gray.rows || + eyeRect.x + eyeRect.width >= gray.cols || eyeRect.y - eyeRect.height >= gray.rows) goto noeye; + eyeROI = gray(eyeRect); - glm::vec2 eyeVector(0,0); if (!optData.noEyes) { eyeVector = eyeDirection(eyeROI); // run pupil tracking algorithm and get look direction } +noeye: + //send control information to graphics float faceSize = landmarks[biggestFace][14].x - landmarks[biggestFace][2].x;