From 4222f903ccbd34f46eff4ee6ae4b42abbc379813 Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Wed, 29 Nov 2017 22:10:51 -0800 Subject: opencv: facedetect: signal gaze direction with color THIS CHANGE IS NOT MEANT TO BE UPSTREAMED. This is just a mod. --- ext/opencv/gstfacedetect.cpp | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'ext/opencv/gstfacedetect.cpp') diff --git a/ext/opencv/gstfacedetect.cpp b/ext/opencv/gstfacedetect.cpp index 1b0d2d474..c2b101669 100644 --- a/ext/opencv/gstfacedetect.cpp +++ b/ext/opencv/gstfacedetect.cpp @@ -759,20 +759,21 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf, } if (filter->display) { - Point center; - Size axes; + Point f_center, center; + Size f_axes, axes; gdouble w, h; + guint aim = 0; /* unset. 1=r, 2=left */ + gint cb = 255 - ((i & 3) << 7); gint cg = 255 - ((i & 12) << 5); gint cr = 255 - ((i & 48) << 3); w = r.width / 2; h = r.height / 2; - center.x = cvRound ((r.x + w)); - center.y = cvRound ((r.y + h)); - axes.width = w; - axes.height = h * 1.25; /* tweak for face form */ - ellipse (img, center, axes, 0, 0, 360, Scalar (cr, cg, cb), 3, 8, 0); + f_center.x = cvRound ((r.x + w)); + f_center.y = cvRound ((r.y + h)); + f_axes.width = w; + f_axes.height = h * 1.25; /* tweak for face form */ if (have_nose) { Rect sr = nose[0]; @@ -781,10 +782,18 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf, h = sr.height / 2; center.x = cvRound ((rnx + sr.x + w)); center.y = cvRound ((rny + sr.y + h)); + + /* left/right toggle */ + if (center.x > f_center.x) + aim = 1; + else if (center.x < f_center.x) + aim = 2; + axes.width = w; axes.height = h * 1.25; /* tweak for nose form */ ellipse (img, center, axes, 0, 0, 360, Scalar (cr, cg, cb), 1, 8, 0); } + if (have_mouth) { Rect sr = mouth[0]; @@ -792,10 +801,34 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf, h = sr.height / 2; center.x = cvRound ((rmx + sr.x + w)); center.y = cvRound ((rmy + sr.y + h)); + + if (!aim) { + if (center.x > f_center.x) + aim = 1; + else if (center.x < f_center.x) + aim = 2; + } + axes.width = w * 1.5; /* tweak for mouth form */ axes.height = h; ellipse (img, center, axes, 0, 0, 360, Scalar (cr, cg, cb), 1, 8, 0); } + + /* Face ellipse */ + switch (aim) { + case 1: + ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (cr, 0, 0), + 3, 8, 0); + break; + case 2: + ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (0, 0, cb), + 3, 8, 0); + break; + default: + ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (cr, cg, cb), + 3, 8, 0); + } + if (have_eyes) { Rect sr = eyes[0]; -- cgit v1.2.3