summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>2017-12-05 17:11:41 -0800
committerReynaldo H. Verdejo Pinochet <reynaldo@freedesktop.org>2019-04-17 15:48:41 -0700
commitbf51dec8dcaa9a3b2d0451cf26f530444ced5c0a (patch)
tree84ec455ff58721e38baa48c943ed2315a3f47bab
parent969d32881c3d388eac60d6a99e792b3f1296e6fa (diff)
opencv: facedetect: Add adaptive off-center dampingopencv
This is a naive adaptive-damping implementation for out-of-center detection flickering. This modification makes it so a the damping factor is not harcoded but computed. Default is 5% of magnitude. Additionally: Add braces around multiline if statement body (for clarity)
-rw-r--r--ext/opencv/gstfacedetect.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/opencv/gstfacedetect.cpp b/ext/opencv/gstfacedetect.cpp
index e78e4c43c..1f351ee3a 100644
--- a/ext/opencv/gstfacedetect.cpp
+++ b/ext/opencv/gstfacedetect.cpp
@@ -595,7 +595,11 @@ gst_face_detect_run_detector (GstFaceDetect * filter,
}
}
+/**
+ * Delta percentaje after wich position is considered off-center
+ */
#define LINEAR_DAMPING_FACTOR 5
+
/**
* @gst_face_detect_get_leaning_side
*
@@ -603,12 +607,17 @@ gst_face_detect_run_detector (GstFaceDetect * filter,
* @pos: Object x coordinate
* @ref_pos: Reference x coordinate
* @side: result. DIRECTION_RIGHT or DIRECTION_LEFT. Untouched if inconclusive
+ * @displacement: Magnitude of min to max ramp
*/
static inline void
-gst_face_detect_get_leaning_side (guint *side, gint reference, gint position) {
+gst_face_detect_get_leaning_side (guint *side, gint reference, gint position,
+ guint displacement) {
+
g_assert (side);
- if (ABS (position - reference) < LINEAR_DAMPING_FACTOR)
+ displacement = displacement * LINEAR_DAMPING_FACTOR / 100;
+
+ if ((guint)ABS (position - reference) <= displacement)
return;
if (position > reference)
@@ -812,7 +821,8 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
center.y = cvRound ((rny + sr.y + h));
/* left/right toggle */
- gst_face_detect_get_leaning_side (&aim, f_center.x, center.x);
+ gst_face_detect_get_leaning_side (&aim, f_center.x, center.x,
+ r.width);
axes.width = w;
axes.height = h * 1.25; /* tweak for nose form */
@@ -827,8 +837,10 @@ 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)
- gst_face_detect_get_leaning_side (&aim, f_center.x, center.x);
+ if (!aim) {
+ gst_face_detect_get_leaning_side (&aim, f_center.x, center.x,
+ r.width);
+ }
axes.width = w * 1.5; /* tweak for mouth form */
axes.height = h;