diff --git a/EyeTab/gaze_system.cpp b/EyeTab/gaze_system.cpp index 3b7fecd..497c3eb 100644 --- a/EyeTab/gaze_system.cpp +++ b/EyeTab/gaze_system.cpp @@ -92,7 +92,7 @@ void track_gaze(Mat& frame_bgr, Mat& frame_gray) { Rect eye0_roi_ref = roiAround(eye0_roi.tl() + c0, (int) (eye_centre_dist * EYE_PAIR_DIST_ROI_RATIO)); Rect eye1_roi_ref = roiAround(eye1_roi.tl() + c1, (int) (eye_centre_dist * EYE_PAIR_DIST_ROI_RATIO)); - // If a ROI lies outside capture frame bounds, break + // If a ROI lies outside capture frame bounds, terminate early Rect capFrameRect = Rect(Point(0,0), frame_bgr.size()); if (eye0_roi_ref != (capFrameRect & eye0_roi_ref) || eye1_roi_ref != (capFrameRect & eye1_roi_ref)) return; diff --git a/EyeTab/get_eyelids.cpp b/EyeTab/get_eyelids.cpp index 445ce45..bd8b42b 100644 --- a/EyeTab/get_eyelids.cpp +++ b/EyeTab/get_eyelids.cpp @@ -11,18 +11,18 @@ using namespace std; using namespace cv; -// Distance from eye-centers to guessed canthi positions +// distance from eye-centers to guessed canthi positions const double CANTH_HORIZ_RATIO = 0.2; const double CANTH_VERT_RATIO = 0.08; -// Returns two eye-corners (canthi) for a given eye, and between-eye vector +// returns two eye-corners (canthi) for a given eye, and between-eye vector vector guess_eye_corners(Point2i& eye_center, Point2i& eye_cs_vec){ float eye_dist = norm(eye_cs_vec); Point2f v_norm = normVec(eye_cs_vec); // normalized vec along eye-pair line Point2f v_perp = Point2f(v_norm.y, v_norm.x); // perp. vec to eye-pair line - // Guess positions of two canthi offset from eye-center + // guess positions of two canthi offset from eye-center vector canthi; Point2i v1 = v_norm * eye_dist * CANTH_HORIZ_RATIO, v2 = v_perp * eye_dist * CANTH_VERT_RATIO; // Use copy-initialize to avoid overload ambiguity canthi.push_back(eye_center - v1 - v2); @@ -31,16 +31,16 @@ vector guess_eye_corners(Point2i& eye_center, Point2i& eye_cs_vec){ return canthi; } -// Offset gradient maxima to push eyelid below incorrect limbus pts +// offset gradient maxima to push eyelid below incorrect limbus pts const double EYELID_OFFSET_RATIO = 0.1; -// Takes the point where dark eye-shadow meets lighter skin in the pixel column of the eye-center +// takes the point where dark eye-shadow meets lighter skin in the pixel column of the eye-center Point find_upper_eyelid_pt(Point2i& eye_center, const Mat& eye_c_col){ Mat filter_col; Sobel(eye_c_col, filter_col, -1, 0, 1, 3); - // Find filter maximum in the top half of the ROI + // find filter maximum in the top half of the ROI int maxIdx[2]; minMaxIdx(filter_col.rowRange(0, filter_col.rows/3), NULL, NULL, NULL, maxIdx); @@ -53,14 +53,14 @@ Mat get_upper_eyelid(Point2i& eye_center, Point2i& eye_cs_vec, Mat& eye_bgr){ cvtColor(eye_bgr, eye_grey, CV_BGR2GRAY); GaussianBlur(eye_grey,eye_grey,Size(5,5),0); - // Invert color to find correct dark > light transition + // invert color to find correct dark > light transition eye_grey = 255-eye_grey; // pts is 3-long vector for internal and external canthi, and upper-eyelid point vector pts = guess_eye_corners(eye_center, eye_cs_vec); pts.push_back(find_upper_eyelid_pt(eye_center, eye_grey.col(eye_bgr.size().width/2))); - // Make matrices and solve for parabola intersecting the 3 points + // make matrices and solve for parabola intersecting the 3 points float mat_a[3][3] = { {pts[0].x * pts[0].x, pts[0].x, 1}, {pts[1].x * pts[1].x, pts[1].x, 1}, @@ -73,10 +73,11 @@ Mat get_upper_eyelid(Point2i& eye_center, Point2i& eye_cs_vec, Mat& eye_bgr){ Mat A(3, 3, CV_32F, &mat_a), B(3, 1, CV_32F, &mat_b); - // Return parabola in the form of a*x^2 + b*x + c as ( Mat of [a, b, c] ) + // return parabola in the form of a*x^2 + b*x + c as ( Mat of [a, b, c] ) return A.inv() * B; } +// remove limbus points that lie outside eyelid vector filter_poss_limb_pts(vector& poss_limb_pts, Mat& parabola, Point2i& roi_tl){ vector pts_to_return; @@ -84,8 +85,8 @@ vector filter_poss_limb_pts(vector& poss_limb_pts, Mat& parabo float x, y; for (Point2f& p : poss_limb_pts){ - y = p.y + roi_tl.y, x = p.x + roi_tl.x; // Shift limbus points from refined eye-roi coords - if (y > a*x*x + b*x + c) pts_to_return.push_back(p); // Only return a point if below upper eyelid parabola + y = p.y + roi_tl.y, x = p.x + roi_tl.x; // shift limbus points from refined eye-roi coords + if (y > a*x*x + b*x + c) pts_to_return.push_back(p); // only return a point if below upper eyelid parabola } return pts_to_return; @@ -96,7 +97,7 @@ void draw_eyelid(Mat& img, Mat& parabola, Rect& roi, Scalar color = RED){ float a = parabola.at(0), b = parabola.at(1), c = parabola.at(2); // Get parabola params - // Approximate eyelid with a poly-line, at x-intervals of EYELID_PARABOLA_GAP + // approximate eyelid with a poly-line, at x-intervals of EYELID_PARABOLA_GAP for (int x=roi.x; x