Fix crash when eye roi outside of view

This commit is contained in:
Epicalert 2021-11-12 19:08:21 +08:00
parent c06f6beae6
commit 57ad5cd47a
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
2 changed files with 8 additions and 2 deletions

View file

@ -9,7 +9,6 @@
- model copyright and authors - model copyright and authors
## Bugs ## Bugs
- crash when eye goes outside of roi
- incorrect appdata location on Windows - incorrect appdata location on Windows
# Whenever # Whenever

View file

@ -170,13 +170,20 @@ void cvFrame() {
cv::rectangle(frame, eyeRect, cv::Scalar(255, 255, 255)); cv::rectangle(frame, eyeRect, cv::Scalar(255, 255, 255));
cv::Mat eyeROI; 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); eyeROI = gray(eyeRect);
glm::vec2 eyeVector(0,0);
if (!optData.noEyes) { if (!optData.noEyes) {
eyeVector = eyeDirection(eyeROI); // run pupil tracking algorithm and get look direction eyeVector = eyeDirection(eyeROI); // run pupil tracking algorithm and get look direction
} }
noeye:
//send control information to graphics //send control information to graphics
float faceSize = landmarks[biggestFace][14].x - landmarks[biggestFace][2].x; float faceSize = landmarks[biggestFace][14].x - landmarks[biggestFace][2].x;