summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>2017-12-01 15:03:44 -0800
committerReynaldo H. Verdejo Pinochet <reynaldo@freedesktop.org>2019-04-17 15:48:41 -0700
commit11b765b975abd0aee749fbc562c6d5893e86aa57 (patch)
tree91b0244ec533a6dbd109a14c492013b4c2ed8592
parent4222f903ccbd34f46eff4ee6ae4b42abbc379813 (diff)
opencv: facedetect: factor out right/left determination logic
Additionally: Swap colors so that RED means leaning right
-rw-r--r--ext/opencv/gstfacedetect.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/ext/opencv/gstfacedetect.cpp b/ext/opencv/gstfacedetect.cpp
index c2b101669..13f201dff 100644
--- a/ext/opencv/gstfacedetect.cpp
+++ b/ext/opencv/gstfacedetect.cpp
@@ -132,6 +132,12 @@ enum
PROP_MIN_STDDEV
};
+enum
+{
+ DIRECTION_INCONCLUSIVE = 0,
+ DIRECTION_RIGHT,
+ DIRECTION_LEFT
+};
/*
* GstOpencvFaceDetectFlags:
@@ -589,6 +595,24 @@ gst_face_detect_run_detector (GstFaceDetect * filter,
}
}
+/**
+ * @gst_face_detect_get_leaning_side
+ *
+ * Figures out what side of a reference a certain cuantity falls into
+ * @pos: Object x coordinate
+ * @ref_pos: Reference x coordinate
+ * @side: result. DIRECTION_RIGHT or DIRECTION_LEFT. Untouched if inconclusive
+ */
+static inline void
+gst_face_detect_get_leaning_side (guint *side, gint reference, gint position) {
+ g_assert (side);
+
+ if (position > reference)
+ *side = DIRECTION_LEFT;
+ else if (position < reference)
+ *side = DIRECTION_RIGHT;
+}
+
/*
* Performs the face detection
*/
@@ -762,7 +786,7 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
Point f_center, center;
Size f_axes, axes;
gdouble w, h;
- guint aim = 0; /* unset. 1=r, 2=left */
+ guint aim = DIRECTION_INCONCLUSIVE;
gint cb = 255 - ((i & 3) << 7);
gint cg = 255 - ((i & 12) << 5);
@@ -784,10 +808,7 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
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;
+ gst_face_detect_get_leaning_side (&aim, f_center.x, center.x);
axes.width = w;
axes.height = h * 1.25; /* tweak for nose form */
@@ -802,12 +823,8 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
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;
- }
+ if (!aim)
+ gst_face_detect_get_leaning_side (&aim, f_center.x, center.x);
axes.width = w * 1.5; /* tweak for mouth form */
axes.height = h;
@@ -816,14 +833,15 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
/* Face ellipse */
switch (aim) {
- case 1:
+ case DIRECTION_RIGHT:
ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (cr, 0, 0),
3, 8, 0);
break;
- case 2:
+ case DIRECTION_LEFT:
ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (0, 0, cb),
3, 8, 0);
break;
+ case DIRECTION_INCONCLUSIVE:
default:
ellipse (mtxOrg, f_center, f_axes, 0, 0, 360, Scalar (cr, cg, cb),
3, 8, 0);