mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
facedetect: Add more parameters
Expose the parameters of cvHaarDetectObjects in facedetect element.
This commit is contained in:
parent
27fedbb352
commit
19ba4c8d19
2 changed files with 112 additions and 2 deletions
|
@ -68,6 +68,11 @@ GST_DEBUG_CATEGORY_STATIC (gst_facedetect_debug);
|
|||
#define GST_CAT_DEFAULT gst_facedetect_debug
|
||||
|
||||
#define DEFAULT_PROFILE "/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"
|
||||
#define DEFAULT_SCALE_FACTOR 1.1
|
||||
#define DEFAULT_FLAGS 0
|
||||
#define DEFAULT_MIN_NEIGHBORS 3
|
||||
#define DEFAULT_MIN_SIZE_WIDTH 0
|
||||
#define DEFAULT_MIN_SIZE_HEIGHT 0
|
||||
|
||||
/* Filter signals and args */
|
||||
enum
|
||||
|
@ -80,9 +85,50 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_DISPLAY,
|
||||
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_DETECT_HAAR_DO_CANNY_PRUNING = (1 << 0)
|
||||
} GstOpencvFaceDetectFlags;
|
||||
|
||||
#define GST_TYPE_OPENCV_FACE_DETECT_FLAGS (gst_opencv_face_detect_flags_get_type())
|
||||
|
||||
static void
|
||||
register_gst_opencv_face_detect_flags (GType * id)
|
||||
{
|
||||
static const GFlagsValue values[] = {
|
||||
{(guint) GST_OPENCV_FACE_DETECT_HAAR_DO_CANNY_PRUNING,
|
||||
"Do Canny edge detection to discard some regions", "do-canny-pruning"},
|
||||
{0, NULL, NULL}
|
||||
};
|
||||
*id = g_flags_register_static ("GstOpencvFaceDetectFlags", values);
|
||||
}
|
||||
|
||||
static GType
|
||||
gst_opencv_face_detect_flags_get_type (void)
|
||||
{
|
||||
static GType id;
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
g_once (&once, (GThreadFunc) register_gst_opencv_face_detect_flags, &id);
|
||||
return id;
|
||||
}
|
||||
|
||||
/* the capabilities of the inputs and outputs.
|
||||
*/
|
||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
|
@ -178,6 +224,28 @@ gst_facedetect_class_init (GstfacedetectClass * klass)
|
|||
g_param_spec_string ("profile", "Profile",
|
||||
"Location of Haar cascade file to use for face detection",
|
||||
DEFAULT_PROFILE, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class, PROP_FLAGS,
|
||||
g_param_spec_flags ("flags", "Flags", "Flags to cvHaarDetectObjects",
|
||||
GST_TYPE_OPENCV_FACE_DETECT_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));
|
||||
}
|
||||
|
||||
/* initialize the new element
|
||||
|
@ -190,6 +258,11 @@ gst_facedetect_init (Gstfacedetect * filter, GstfacedetectClass * gclass)
|
|||
{
|
||||
filter->profile = g_strdup (DEFAULT_PROFILE);
|
||||
filter->display = TRUE;
|
||||
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_facedetect_load_profile (filter);
|
||||
|
||||
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
|
||||
|
@ -211,6 +284,21 @@ gst_facedetect_set_property (GObject * object, guint prop_id,
|
|||
case PROP_DISPLAY:
|
||||
filter->display = g_value_get_boolean (value);
|
||||
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;
|
||||
|
@ -230,6 +318,21 @@ gst_facedetect_get_property (GObject * object, guint prop_id,
|
|||
case PROP_DISPLAY:
|
||||
g_value_set_boolean (value, filter->display);
|
||||
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;
|
||||
|
@ -306,7 +409,9 @@ gst_facedetect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
|
|||
|
||||
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 (faces && faces->total > 0) {
|
||||
msg = gst_facedetect_message_new (filter, buf);
|
||||
|
|
|
@ -72,6 +72,11 @@ struct _Gstfacedetect
|
|||
gboolean display;
|
||||
|
||||
gchar *profile;
|
||||
gdouble scale_factor;
|
||||
gint min_neighbors;
|
||||
gint flags;
|
||||
gint min_size_width;
|
||||
gint min_size_height;
|
||||
|
||||
IplImage *cvGray;
|
||||
CvHaarClassifierCascade *cvCascade;
|
||||
|
|
Loading…
Reference in a new issue