diff options
author | Robert Jobbagy <jobbagy.robert@gmail.com> | 2014-07-30 16:32:01 -0300 |
---|---|---|
committer | Thiago Santos <thiagoss@osg.samsung.com> | 2014-07-30 16:43:10 -0300 |
commit | bd3cefeecc732cb0aa376a508165bcd04e9f950f (patch) | |
tree | ca3c02de5b948e4c61182df0d56d64d7ef0bf36e /ext | |
parent | 43a4498569f1939e409a08b88445cafe10e26f94 (diff) |
faceblur: facedetect: add properties to faceblur
Makes faceblur have the same properties as facedetect. Also improves
the standard defaults and makes them the same in the 2 elements
Diffstat (limited to 'ext')
-rw-r--r-- | ext/opencv/gstfaceblur.c | 112 | ||||
-rw-r--r-- | ext/opencv/gstfaceblur.h | 6 | ||||
-rw-r--r-- | ext/opencv/gstfacedetect.c | 9 | ||||
-rw-r--r-- | ext/opencv/gstfacedetect.h | 1 |
4 files changed, 120 insertions, 8 deletions
diff --git a/ext/opencv/gstfaceblur.c b/ext/opencv/gstfaceblur.c index ccae0dcad..cadeaedb4 100644 --- a/ext/opencv/gstfaceblur.c +++ b/ext/opencv/gstfaceblur.c @@ -3,6 +3,7 @@ * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org> * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> * Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com> + * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -71,13 +72,58 @@ GST_DEBUG_CATEGORY_STATIC (gst_face_blur_debug); #define DEFAULT_PROFILE OPENCV_PREFIX G_DIR_SEPARATOR_S "share" \ G_DIR_SEPARATOR_S "opencv" G_DIR_SEPARATOR_S "haarcascades" \ G_DIR_SEPARATOR_S "haarcascade_frontalface_default.xml" +#define DEFAULT_SCALE_FACTOR 1.25 +#define DEFAULT_FLAGS CV_HAAR_DO_CANNY_PRUNING +#define DEFAULT_MIN_NEIGHBORS 3 +#define DEFAULT_MIN_SIZE_WIDTH 30 +#define DEFAULT_MIN_SIZE_HEIGHT 30 enum { PROP_0, - PROP_PROFILE + PROP_PROFILE, + PROP_SCALE_FACTOR, + PROP_MIN_NEIGHBORS, + PROP_FLAGS, + PROP_MIN_SIZE_WIDTH, + PROP_MIN_SIZE_HEIGHT }; +/** + * GstOpencvFaceDetectFlags: + * @GST_CAMERABIN_FLAG_SOURCE_RESIZE: enable video crop and scale + * after capture + * + * Flags parameter to OpenCV's cvHaarDetectObjects function. + */ +typedef enum +{ + GST_OPENCV_FACE_BLUR_HAAR_DO_CANNY_PRUNING = (1 << 0) +} GstOpencvFaceBlurFlags; + +#define GST_TYPE_OPENCV_FACE_BLUR_FLAGS (gst_opencv_face_blur_flags_get_type()) + +static void +register_gst_opencv_face_blur_flags (GType * id) +{ + static const GFlagsValue values[] = { + {(guint) GST_OPENCV_FACE_BLUR_HAAR_DO_CANNY_PRUNING, + "Do Canny edge detection to discard some regions", "do-canny-pruning"}, + {0, NULL, NULL} + }; + *id = g_flags_register_static ("GstOpencvFaceBlurFlags", values); +} + +static GType +gst_opencv_face_blur_flags_get_type (void) +{ + static GType id; + static GOnce once = G_ONCE_INIT; + + g_once (&once, (GThreadFunc) register_gst_opencv_face_blur_flags, &id); + return id; +} + /* the capabilities of the inputs and outputs. */ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", @@ -151,12 +197,34 @@ gst_face_blur_class_init (GstFaceBlurClass * klass) g_param_spec_string ("profile", "Profile", "Location of Haar cascade file to use for face blurion", DEFAULT_PROFILE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_FLAGS, + g_param_spec_flags ("flags", "Flags", "Flags to cvHaarDetectObjects", + GST_TYPE_OPENCV_FACE_BLUR_FLAGS, DEFAULT_FLAGS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_SCALE_FACTOR, + g_param_spec_double ("scale-factor", "Scale factor", + "Factor by which the windows is scaled after each scan", + 1.1, 10.0, DEFAULT_SCALE_FACTOR, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_MIN_NEIGHBORS, + g_param_spec_int ("min-neighbors", "Mininum neighbors", + "Minimum number (minus 1) of neighbor rectangles that makes up " + "an object", 0, G_MAXINT, DEFAULT_MIN_NEIGHBORS, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_MIN_SIZE_WIDTH, + g_param_spec_int ("min-size-width", "Minimum size width", + "Minimum window width size", 0, G_MAXINT, DEFAULT_MIN_SIZE_WIDTH, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_MIN_SIZE_HEIGHT, + g_param_spec_int ("min-size-height", "Minimum size height", + "Minimum window height size", 0, G_MAXINT, DEFAULT_MIN_SIZE_HEIGHT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); gst_element_class_set_static_metadata (element_class, "faceblur", "Filter/Effect/Video", "Blurs faces in images and videos", - "Michael Sheldon <mike@mikeasoft.com>"); + "Michael Sheldon <mike@mikeasoft.com>,Robert Jobbagy <jobbagy.robert@gmail.com>"); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_factory)); @@ -175,6 +243,11 @@ gst_face_blur_init (GstFaceBlur * filter) filter->profile = g_strdup (DEFAULT_PROFILE); gst_face_blur_load_profile (filter); filter->sent_profile_load_failed_msg = FALSE; + filter->scale_factor = DEFAULT_SCALE_FACTOR; + filter->min_neighbors = DEFAULT_MIN_NEIGHBORS; + filter->flags = DEFAULT_FLAGS; + filter->min_size_width = DEFAULT_MIN_SIZE_WIDTH; + filter->min_size_height = DEFAULT_MIN_SIZE_HEIGHT; gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter), TRUE); @@ -193,6 +266,21 @@ gst_face_blur_set_property (GObject * object, guint prop_id, gst_face_blur_load_profile (filter); filter->sent_profile_load_failed_msg = FALSE; break; + case PROP_SCALE_FACTOR: + filter->scale_factor = g_value_get_double (value); + break; + case PROP_MIN_NEIGHBORS: + filter->min_neighbors = g_value_get_int (value); + break; + case PROP_MIN_SIZE_WIDTH: + filter->min_size_width = g_value_get_int (value); + break; + case PROP_MIN_SIZE_HEIGHT: + filter->min_size_height = g_value_get_int (value); + break; + case PROP_FLAGS: + filter->flags = g_value_get_flags (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -209,6 +297,21 @@ gst_face_blur_get_property (GObject * object, guint prop_id, case PROP_PROFILE: g_value_set_string (value, filter->profile); break; + case PROP_SCALE_FACTOR: + g_value_set_double (value, filter->scale_factor); + break; + case PROP_MIN_NEIGHBORS: + g_value_set_int (value, filter->min_neighbors); + break; + case PROP_MIN_SIZE_WIDTH: + g_value_set_int (value, filter->min_size_width); + break; + case PROP_MIN_SIZE_HEIGHT: + g_value_set_int (value, filter->min_size_height); + break; + case PROP_FLAGS: + g_value_set_flags (value, filter->flags); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -260,9 +363,10 @@ gst_face_blur_transform_ip (GstOpencvVideoFilter * transform, faces = cvHaarDetectObjects (filter->cvGray, filter->cvCascade, - filter->cvStorage, 1.1, 2, 0, cvSize (30, 30) + filter->cvStorage, filter->scale_factor, filter->min_neighbors, + filter->flags, cvSize (filter->min_size_width, filter->min_size_height) #if (CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >= 2) - , cvSize (0, 0) + , cvSize (filter->min_size_width + 2, filter->min_size_height + 2) #endif ); diff --git a/ext/opencv/gstfaceblur.h b/ext/opencv/gstfaceblur.h index 26804bc8d..a6ee28e64 100644 --- a/ext/opencv/gstfaceblur.h +++ b/ext/opencv/gstfaceblur.h @@ -3,6 +3,7 @@ * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org> * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> * Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com> + * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -78,6 +79,11 @@ struct _GstFaceBlur gchar *profile; gboolean display; + gdouble scale_factor; + gint min_neighbors; + gint flags; + gint min_size_width; + gint min_size_height; IplImage *cvGray; CvHaarClassifierCascade *cvCascade; diff --git a/ext/opencv/gstfacedetect.c b/ext/opencv/gstfacedetect.c index 5789b46d2..96af19ea3 100644 --- a/ext/opencv/gstfacedetect.c +++ b/ext/opencv/gstfacedetect.c @@ -4,6 +4,7 @@ * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> * Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com> * Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net> + * Copyright (C) 2014 Robert Jobbagy <jobbagy.robert@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -91,11 +92,11 @@ GST_DEBUG_CATEGORY_STATIC (gst_face_detect_debug); #define DEFAULT_NOSE_PROFILE HAAR_CASCADES_DIR "haarcascade_mcs_nose.xml" #define DEFAULT_MOUTH_PROFILE HAAR_CASCADES_DIR "haarcascade_mcs_mouth.xml" #define DEFAULT_EYES_PROFILE HAAR_CASCADES_DIR "haarcascade_mcs_eyepair_small.xml" -#define DEFAULT_SCALE_FACTOR 1.1 -#define DEFAULT_FLAGS 0 +#define DEFAULT_SCALE_FACTOR 1.25 +#define DEFAULT_FLAGS CV_HAAR_DO_CANNY_PRUNING #define DEFAULT_MIN_NEIGHBORS 3 -#define DEFAULT_MIN_SIZE_WIDTH 0 -#define DEFAULT_MIN_SIZE_HEIGHT 0 +#define DEFAULT_MIN_SIZE_WIDTH 30 +#define DEFAULT_MIN_SIZE_HEIGHT 30 /* Filter signals and args */ enum diff --git a/ext/opencv/gstfacedetect.h b/ext/opencv/gstfacedetect.h index ac51c5286..a9fdd1f4f 100644 --- a/ext/opencv/gstfacedetect.h +++ b/ext/opencv/gstfacedetect.h @@ -4,6 +4,7 @@ * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> * Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com> * Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net> + * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), |