mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
Bring code in to line with general Gstreamer standards
This commit is contained in:
parent
0961dbefd4
commit
babe97ca50
11 changed files with 390 additions and 386 deletions
|
@ -90,21 +90,16 @@ enum
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
GST_BOILERPLATE (Gstedgedetect, gst_edgedetect, GstElement,
|
GST_BOILERPLATE (Gstedgedetect, gst_edgedetect, GstElement, GST_TYPE_ELEMENT);
|
||||||
GST_TYPE_ELEMENT);
|
|
||||||
|
|
||||||
static void gst_edgedetect_set_property (GObject * object, guint prop_id,
|
static void gst_edgedetect_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
|
@ -120,8 +115,7 @@ gst_edgedetect_finalize (GObject * obj)
|
||||||
{
|
{
|
||||||
Gstedgedetect *filter = GST_EDGEDETECT (obj);
|
Gstedgedetect *filter = GST_EDGEDETECT (obj);
|
||||||
|
|
||||||
if (filter->cvImage != NULL)
|
if (filter->cvImage != NULL) {
|
||||||
{
|
|
||||||
cvReleaseImage (&filter->cvImage);
|
cvReleaseImage (&filter->cvImage);
|
||||||
cvReleaseImage (&filter->cvCEdge);
|
cvReleaseImage (&filter->cvCEdge);
|
||||||
cvReleaseImage (&filter->cvGray);
|
cvReleaseImage (&filter->cvGray);
|
||||||
|
@ -137,11 +131,11 @@ gst_edgedetect_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
||||||
|
|
||||||
gst_element_class_set_details_simple(element_class,
|
gst_element_class_set_details_simple (element_class,
|
||||||
"edgedetect",
|
"edgedetect",
|
||||||
"Filter/Effect/Video",
|
"Filter/Effect/Video",
|
||||||
"Performs canny edge detection on videos and images.",
|
"Performs canny edge detection on videos and images.",
|
||||||
"Michael Sheldon <mike@mikeasoft.com>");
|
"Michael Sheldon <mike@mikeasoft.com>");
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
|
@ -165,17 +159,21 @@ gst_edgedetect_class_init (GstedgedetectClass * klass)
|
||||||
gobject_class->get_property = gst_edgedetect_get_property;
|
gobject_class->get_property = gst_edgedetect_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_MASK,
|
g_object_class_install_property (gobject_class, PROP_MASK,
|
||||||
g_param_spec_boolean ("mask", "Mask", "Sets whether the detected edges should be used as a mask on the original input or not",
|
g_param_spec_boolean ("mask", "Mask",
|
||||||
|
"Sets whether the detected edges should be used as a mask on the original input or not",
|
||||||
TRUE, G_PARAM_READWRITE));
|
TRUE, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
||||||
g_param_spec_int ("threshold1", "Threshold1", "Threshold value for canny edge detection",
|
g_param_spec_int ("threshold1", "Threshold1",
|
||||||
0, 1000, 50, G_PARAM_READWRITE));
|
"Threshold value for canny edge detection", 0, 1000, 50,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
||||||
g_param_spec_int ("threshold2", "Threshold2", "Second threshold value for canny edge detection",
|
g_param_spec_int ("threshold2", "Threshold2",
|
||||||
0, 1000, 150, G_PARAM_READWRITE));
|
"Second threshold value for canny edge detection", 0, 1000, 150,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (gobject_class, PROP_APERTURE,
|
g_object_class_install_property (gobject_class, PROP_APERTURE,
|
||||||
g_param_spec_int ("aperture", "Aperture", "Aperture size for Sobel operator (Must be either 3, 5 or 7",
|
g_param_spec_int ("aperture", "Aperture",
|
||||||
3, 7, 3, G_PARAM_READWRITE));
|
"Aperture size for Sobel operator (Must be either 3, 5 or 7", 3, 7, 3,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the new element
|
/* initialize the new element
|
||||||
|
@ -184,20 +182,19 @@ gst_edgedetect_class_init (GstedgedetectClass * klass)
|
||||||
* initialize instance structure
|
* initialize instance structure
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
gst_edgedetect_init (Gstedgedetect * filter,
|
gst_edgedetect_init (Gstedgedetect * filter, GstedgedetectClass * gclass)
|
||||||
GstedgedetectClass * gclass)
|
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_edgedetect_set_caps));
|
GST_DEBUG_FUNCPTR (gst_edgedetect_set_caps));
|
||||||
gst_pad_set_getcaps_function (filter->sinkpad,
|
gst_pad_set_getcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
gst_pad_set_chain_function (filter->sinkpad,
|
gst_pad_set_chain_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_edgedetect_chain));
|
GST_DEBUG_FUNCPTR (gst_edgedetect_chain));
|
||||||
|
|
||||||
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
gst_pad_set_getcaps_function (filter->srcpad,
|
gst_pad_set_getcaps_function (filter->srcpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
|
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||||
|
@ -273,10 +270,10 @@ gst_edgedetect_set_caps (GstPad * pad, GstCaps * caps)
|
||||||
gst_structure_get_int (structure, "width", &width);
|
gst_structure_get_int (structure, "width", &width);
|
||||||
gst_structure_get_int (structure, "height", &height);
|
gst_structure_get_int (structure, "height", &height);
|
||||||
|
|
||||||
filter->cvImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvImage = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
filter->cvCEdge = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvCEdge = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
filter->cvGray = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
|
filter->cvGray = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 1);
|
||||||
filter->cvEdge = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
|
filter->cvEdge = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 1);
|
||||||
|
|
||||||
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
||||||
gst_object_unref (filter);
|
gst_object_unref (filter);
|
||||||
|
@ -296,18 +293,20 @@ gst_edgedetect_chain (GstPad * pad, GstBuffer * buf)
|
||||||
|
|
||||||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||||
|
|
||||||
cvCvtColor(filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
cvCvtColor (filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
||||||
cvSmooth(filter->cvGray, filter->cvEdge, CV_BLUR, 3, 3, 0, 0 );
|
cvSmooth (filter->cvGray, filter->cvEdge, CV_BLUR, 3, 3, 0, 0);
|
||||||
cvNot(filter->cvGray, filter->cvEdge);
|
cvNot (filter->cvGray, filter->cvEdge);
|
||||||
cvCanny(filter->cvGray, filter->cvEdge, filter->threshold1, filter->threshold2, filter->aperture);
|
cvCanny (filter->cvGray, filter->cvEdge, filter->threshold1,
|
||||||
|
filter->threshold2, filter->aperture);
|
||||||
|
|
||||||
cvZero(filter->cvCEdge);
|
cvZero (filter->cvCEdge);
|
||||||
if(filter-> mask) {
|
if (filter->mask) {
|
||||||
cvCopy(filter->cvImage, filter->cvCEdge, filter->cvEdge);
|
cvCopy (filter->cvImage, filter->cvCEdge, filter->cvEdge);
|
||||||
} else {
|
} else {
|
||||||
cvCvtColor(filter->cvEdge, filter->cvCEdge, CV_GRAY2RGB);
|
cvCvtColor (filter->cvEdge, filter->cvCEdge, CV_GRAY2RGB);
|
||||||
}
|
}
|
||||||
gst_buffer_set_data(buf, filter->cvCEdge->imageData, filter->cvCEdge->imageSize);
|
gst_buffer_set_data (buf, filter->cvCEdge->imageData,
|
||||||
|
filter->cvCEdge->imageSize);
|
||||||
|
|
||||||
return gst_pad_push (filter->srcpad, buf);
|
return gst_pad_push (filter->srcpad, buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include <cv.h>
|
#include <cv.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/* #defines don't like whitespacey bits */
|
/* #defines don't like whitespacey bits */
|
||||||
#define GST_TYPE_EDGEDETECT \
|
#define GST_TYPE_EDGEDETECT \
|
||||||
(gst_edgedetect_get_type())
|
(gst_edgedetect_get_type())
|
||||||
|
@ -62,8 +61,7 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDGEDETECT))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDGEDETECT))
|
||||||
#define GST_IS_EDGEDETECT_CLASS(klass) \
|
#define GST_IS_EDGEDETECT_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDGEDETECT))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDGEDETECT))
|
||||||
|
typedef struct _Gstedgedetect Gstedgedetect;
|
||||||
typedef struct _Gstedgedetect Gstedgedetect;
|
|
||||||
typedef struct _GstedgedetectClass GstedgedetectClass;
|
typedef struct _GstedgedetectClass GstedgedetectClass;
|
||||||
|
|
||||||
struct _Gstedgedetect
|
struct _Gstedgedetect
|
||||||
|
@ -79,7 +77,7 @@ struct _Gstedgedetect
|
||||||
IplImage *cvEdge, *cvGray, *cvImage, *cvCEdge;
|
IplImage *cvEdge, *cvGray, *cvImage, *cvCEdge;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstedgedetectClass
|
struct _GstedgedetectClass
|
||||||
{
|
{
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
@ -89,5 +87,4 @@ GType gst_edgedetect_get_type (void);
|
||||||
gboolean gst_edgedetect_plugin_init (GstPlugin * plugin);
|
gboolean gst_edgedetect_plugin_init (GstPlugin * plugin);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_EDGEDETECT_H__ */
|
#endif /* __GST_EDGEDETECT_H__ */
|
||||||
|
|
|
@ -87,21 +87,16 @@ enum
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
GST_BOILERPLATE (Gstfaceblur, gst_faceblur, GstElement,
|
GST_BOILERPLATE (Gstfaceblur, gst_faceblur, GstElement, GST_TYPE_ELEMENT);
|
||||||
GST_TYPE_ELEMENT);
|
|
||||||
|
|
||||||
static void gst_faceblur_set_property (GObject * object, guint prop_id,
|
static void gst_faceblur_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
|
@ -117,10 +112,9 @@ static void gst_faceblur_load_profile (Gstfaceblur * filter);
|
||||||
static void
|
static void
|
||||||
gst_faceblur_finalize (GObject * obj)
|
gst_faceblur_finalize (GObject * obj)
|
||||||
{
|
{
|
||||||
Gstfaceblur *filter = GST_FACEBLUR(obj);
|
Gstfaceblur *filter = GST_FACEBLUR (obj);
|
||||||
|
|
||||||
if (filter->cvImage)
|
if (filter->cvImage) {
|
||||||
{
|
|
||||||
cvReleaseImage (&filter->cvImage);
|
cvReleaseImage (&filter->cvImage);
|
||||||
cvReleaseImage (&filter->cvGray);
|
cvReleaseImage (&filter->cvGray);
|
||||||
}
|
}
|
||||||
|
@ -135,11 +129,11 @@ gst_faceblur_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
||||||
|
|
||||||
gst_element_class_set_details_simple(element_class,
|
gst_element_class_set_details_simple (element_class,
|
||||||
"faceblur",
|
"faceblur",
|
||||||
"Filter/Effect/Video",
|
"Filter/Effect/Video",
|
||||||
"Blurs faces in images and videos",
|
"Blurs faces in images and videos",
|
||||||
"Michael Sheldon <mike@mikeasoft.com>");
|
"Michael Sheldon <mike@mikeasoft.com>");
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
|
@ -163,7 +157,8 @@ gst_faceblur_class_init (GstfaceblurClass * klass)
|
||||||
gobject_class->get_property = gst_faceblur_get_property;
|
gobject_class->get_property = gst_faceblur_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_PROFILE,
|
g_object_class_install_property (gobject_class, PROP_PROFILE,
|
||||||
g_param_spec_string ("profile", "Profile", "Location of Haar cascade file to use for face blurion",
|
g_param_spec_string ("profile", "Profile",
|
||||||
|
"Location of Haar cascade file to use for face blurion",
|
||||||
DEFAULT_PROFILE, G_PARAM_READWRITE));
|
DEFAULT_PROFILE, G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,25 +168,24 @@ gst_faceblur_class_init (GstfaceblurClass * klass)
|
||||||
* initialize instance structure
|
* initialize instance structure
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
gst_faceblur_init (Gstfaceblur * filter,
|
gst_faceblur_init (Gstfaceblur * filter, GstfaceblurClass * gclass)
|
||||||
GstfaceblurClass * gclass)
|
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_faceblur_set_caps));
|
GST_DEBUG_FUNCPTR (gst_faceblur_set_caps));
|
||||||
gst_pad_set_getcaps_function (filter->sinkpad,
|
gst_pad_set_getcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
gst_pad_set_chain_function (filter->sinkpad,
|
gst_pad_set_chain_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_faceblur_chain));
|
GST_DEBUG_FUNCPTR (gst_faceblur_chain));
|
||||||
|
|
||||||
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
gst_pad_set_getcaps_function (filter->srcpad,
|
gst_pad_set_getcaps_function (filter->srcpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
|
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||||
filter->profile = DEFAULT_PROFILE;
|
filter->profile = DEFAULT_PROFILE;
|
||||||
gst_faceblur_load_profile(filter);
|
gst_faceblur_load_profile (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -203,7 +197,7 @@ gst_faceblur_set_property (GObject * object, guint prop_id,
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_PROFILE:
|
case PROP_PROFILE:
|
||||||
filter->profile = g_value_dup_string (value);
|
filter->profile = g_value_dup_string (value);
|
||||||
gst_faceblur_load_profile(filter);
|
gst_faceblur_load_profile (filter);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
@ -243,9 +237,9 @@ gst_faceblur_set_caps (GstPad * pad, GstCaps * caps)
|
||||||
gst_structure_get_int (structure, "width", &width);
|
gst_structure_get_int (structure, "width", &width);
|
||||||
gst_structure_get_int (structure, "height", &height);
|
gst_structure_get_int (structure, "height", &height);
|
||||||
|
|
||||||
filter->cvImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvImage = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
filter->cvGray = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
|
filter->cvGray = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 1);
|
||||||
filter->cvStorage = cvCreateMemStorage(0);
|
filter->cvStorage = cvCreateMemStorage (0);
|
||||||
|
|
||||||
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
||||||
gst_object_unref (filter);
|
gst_object_unref (filter);
|
||||||
|
@ -267,30 +261,36 @@ gst_faceblur_chain (GstPad * pad, GstBuffer * buf)
|
||||||
|
|
||||||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||||
|
|
||||||
cvCvtColor(filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
cvCvtColor (filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
||||||
cvClearMemStorage(filter->cvStorage);
|
cvClearMemStorage (filter->cvStorage);
|
||||||
|
|
||||||
if (filter->cvCascade) {
|
if (filter->cvCascade) {
|
||||||
faces = cvHaarDetectObjects(filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize(30, 30));
|
faces =
|
||||||
|
cvHaarDetectObjects (filter->cvGray, filter->cvCascade,
|
||||||
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
filter->cvStorage, 1.1, 2, 0, cvSize (30, 30));
|
||||||
CvRect* r = (CvRect *) cvGetSeqElem(faces, i);
|
|
||||||
cvSetImageROI(filter->cvImage, *r);
|
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
||||||
cvSmooth(filter->cvImage, filter->cvImage, CV_BLUR, 11, 11, 0, 0);
|
CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
|
||||||
cvSmooth(filter->cvImage, filter->cvImage, CV_GAUSSIAN, 11, 11, 0, 0);
|
cvSetImageROI (filter->cvImage, *r);
|
||||||
cvResetImageROI(filter->cvImage);
|
cvSmooth (filter->cvImage, filter->cvImage, CV_BLUR, 11, 11, 0, 0);
|
||||||
|
cvSmooth (filter->cvImage, filter->cvImage, CV_GAUSSIAN, 11, 11, 0, 0);
|
||||||
|
cvResetImageROI (filter->cvImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_buffer_set_data(buf, filter->cvImage->imageData, filter->cvImage->imageSize);
|
gst_buffer_set_data (buf, filter->cvImage->imageData,
|
||||||
|
filter->cvImage->imageSize);
|
||||||
|
|
||||||
return gst_pad_push (filter->srcpad, buf);
|
return gst_pad_push (filter->srcpad, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void gst_faceblur_load_profile(Gstfaceblur * filter) {
|
static void
|
||||||
filter->cvCascade = (CvHaarClassifierCascade*)cvLoad(filter->profile, 0, 0, 0 );
|
gst_faceblur_load_profile (Gstfaceblur * filter)
|
||||||
|
{
|
||||||
|
filter->cvCascade =
|
||||||
|
(CvHaarClassifierCascade *) cvLoad (filter->profile, 0, 0, 0);
|
||||||
if (!filter->cvCascade) {
|
if (!filter->cvCascade) {
|
||||||
GST_WARNING ("Couldn't load Haar classifier cascade: %s.", filter->profile);
|
GST_WARNING ("Couldn't load Haar classifier cascade: %s.", filter->profile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include <cv.h>
|
#include <cv.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/* #defines don't like whitespacey bits */
|
/* #defines don't like whitespacey bits */
|
||||||
#define GST_TYPE_FACEBLUR \
|
#define GST_TYPE_FACEBLUR \
|
||||||
(gst_faceblur_get_type())
|
(gst_faceblur_get_type())
|
||||||
|
@ -62,8 +61,7 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEBLUR))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEBLUR))
|
||||||
#define GST_IS_FACEBLUR_CLASS(klass) \
|
#define GST_IS_FACEBLUR_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEBLUR))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEBLUR))
|
||||||
|
typedef struct _Gstfaceblur Gstfaceblur;
|
||||||
typedef struct _Gstfaceblur Gstfaceblur;
|
|
||||||
typedef struct _GstfaceblurClass GstfaceblurClass;
|
typedef struct _GstfaceblurClass GstfaceblurClass;
|
||||||
|
|
||||||
struct _Gstfaceblur
|
struct _Gstfaceblur
|
||||||
|
@ -81,7 +79,7 @@ struct _Gstfaceblur
|
||||||
CvMemStorage *cvStorage;
|
CvMemStorage *cvStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstfaceblurClass
|
struct _GstfaceblurClass
|
||||||
{
|
{
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
@ -91,5 +89,4 @@ GType gst_faceblur_get_type (void);
|
||||||
gboolean gst_faceblur_plugin_init (GstPlugin * plugin);
|
gboolean gst_faceblur_plugin_init (GstPlugin * plugin);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_FACEBLUR_H__ */
|
#endif /* __GST_FACEBLUR_H__ */
|
||||||
|
|
|
@ -88,21 +88,16 @@ enum
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
GST_BOILERPLATE (Gstfacedetect, gst_facedetect, GstElement,
|
GST_BOILERPLATE (Gstfacedetect, gst_facedetect, GstElement, GST_TYPE_ELEMENT);
|
||||||
GST_TYPE_ELEMENT);
|
|
||||||
|
|
||||||
static void gst_facedetect_set_property (GObject * object, guint prop_id,
|
static void gst_facedetect_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
|
@ -118,10 +113,9 @@ static void gst_facedetect_load_profile (Gstfacedetect * filter);
|
||||||
static void
|
static void
|
||||||
gst_facedetect_finalize (GObject * obj)
|
gst_facedetect_finalize (GObject * obj)
|
||||||
{
|
{
|
||||||
Gstfacedetect *filter = GST_FACEDETECT(obj);
|
Gstfacedetect *filter = GST_FACEDETECT (obj);
|
||||||
|
|
||||||
if (filter->cvImage)
|
if (filter->cvImage) {
|
||||||
{
|
|
||||||
cvReleaseImage (&filter->cvImage);
|
cvReleaseImage (&filter->cvImage);
|
||||||
cvReleaseImage (&filter->cvGray);
|
cvReleaseImage (&filter->cvGray);
|
||||||
}
|
}
|
||||||
|
@ -136,11 +130,11 @@ gst_facedetect_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
||||||
|
|
||||||
gst_element_class_set_details_simple(element_class,
|
gst_element_class_set_details_simple (element_class,
|
||||||
"facedetect",
|
"facedetect",
|
||||||
"Filter/Effect/Video",
|
"Filter/Effect/Video",
|
||||||
"Performs face detection on videos and images, providing detected positions via bus messages",
|
"Performs face detection on videos and images, providing detected positions via bus messages",
|
||||||
"Michael Sheldon <mike@mikeasoft.com>");
|
"Michael Sheldon <mike@mikeasoft.com>");
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
|
@ -164,10 +158,12 @@ gst_facedetect_class_init (GstfacedetectClass * klass)
|
||||||
gobject_class->get_property = gst_facedetect_get_property;
|
gobject_class->get_property = gst_facedetect_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
||||||
g_param_spec_boolean ("display", "Display", "Sets whether the detected faces should be highlighted in the output",
|
g_param_spec_boolean ("display", "Display",
|
||||||
|
"Sets whether the detected faces should be highlighted in the output",
|
||||||
TRUE, G_PARAM_READWRITE));
|
TRUE, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (gobject_class, PROP_PROFILE,
|
g_object_class_install_property (gobject_class, PROP_PROFILE,
|
||||||
g_param_spec_string ("profile", "Profile", "Location of Haar cascade file to use for face detection",
|
g_param_spec_string ("profile", "Profile",
|
||||||
|
"Location of Haar cascade file to use for face detection",
|
||||||
DEFAULT_PROFILE, G_PARAM_READWRITE));
|
DEFAULT_PROFILE, G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,26 +173,25 @@ gst_facedetect_class_init (GstfacedetectClass * klass)
|
||||||
* initialize instance structure
|
* initialize instance structure
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
gst_facedetect_init (Gstfacedetect * filter,
|
gst_facedetect_init (Gstfacedetect * filter, GstfacedetectClass * gclass)
|
||||||
GstfacedetectClass * gclass)
|
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_facedetect_set_caps));
|
GST_DEBUG_FUNCPTR (gst_facedetect_set_caps));
|
||||||
gst_pad_set_getcaps_function (filter->sinkpad,
|
gst_pad_set_getcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
gst_pad_set_chain_function (filter->sinkpad,
|
gst_pad_set_chain_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_facedetect_chain));
|
GST_DEBUG_FUNCPTR (gst_facedetect_chain));
|
||||||
|
|
||||||
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
gst_pad_set_getcaps_function (filter->srcpad,
|
gst_pad_set_getcaps_function (filter->srcpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
|
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||||
filter->profile = DEFAULT_PROFILE;
|
filter->profile = DEFAULT_PROFILE;
|
||||||
filter->display = TRUE;
|
filter->display = TRUE;
|
||||||
gst_facedetect_load_profile(filter);
|
gst_facedetect_load_profile (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -208,7 +203,7 @@ gst_facedetect_set_property (GObject * object, guint prop_id,
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_PROFILE:
|
case PROP_PROFILE:
|
||||||
filter->profile = g_value_dup_string (value);
|
filter->profile = g_value_dup_string (value);
|
||||||
gst_facedetect_load_profile(filter);
|
gst_facedetect_load_profile (filter);
|
||||||
break;
|
break;
|
||||||
case PROP_DISPLAY:
|
case PROP_DISPLAY:
|
||||||
filter->display = g_value_get_boolean (value);
|
filter->display = g_value_get_boolean (value);
|
||||||
|
@ -254,9 +249,9 @@ gst_facedetect_set_caps (GstPad * pad, GstCaps * caps)
|
||||||
gst_structure_get_int (structure, "width", &width);
|
gst_structure_get_int (structure, "width", &width);
|
||||||
gst_structure_get_int (structure, "height", &height);
|
gst_structure_get_int (structure, "height", &height);
|
||||||
|
|
||||||
filter->cvImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvImage = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
filter->cvGray = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
|
filter->cvGray = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 1);
|
||||||
filter->cvStorage = cvCreateMemStorage(0);
|
filter->cvStorage = cvCreateMemStorage (0);
|
||||||
|
|
||||||
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
||||||
gst_object_unref (filter);
|
gst_object_unref (filter);
|
||||||
|
@ -278,20 +273,22 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf)
|
||||||
|
|
||||||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||||
|
|
||||||
cvCvtColor(filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
cvCvtColor (filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
||||||
cvClearMemStorage(filter->cvStorage);
|
cvClearMemStorage (filter->cvStorage);
|
||||||
|
|
||||||
if (filter->cvCascade) {
|
if (filter->cvCascade) {
|
||||||
faces = cvHaarDetectObjects(filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize(30, 30));
|
faces =
|
||||||
|
cvHaarDetectObjects (filter->cvGray, filter->cvCascade,
|
||||||
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
filter->cvStorage, 1.1, 2, 0, cvSize (30, 30));
|
||||||
CvRect* r = (CvRect *) cvGetSeqElem(faces, i);
|
|
||||||
|
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
||||||
|
CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
|
||||||
|
|
||||||
GstStructure *s = gst_structure_new ("face",
|
GstStructure *s = gst_structure_new ("face",
|
||||||
"x", G_TYPE_UINT, r->x,
|
"x", G_TYPE_UINT, r->x,
|
||||||
"y", G_TYPE_UINT, r->y,
|
"y", G_TYPE_UINT, r->y,
|
||||||
"width", G_TYPE_UINT, r->width,
|
"width", G_TYPE_UINT, r->width,
|
||||||
"height", G_TYPE_UINT, r->height, NULL);
|
"height", G_TYPE_UINT, r->height, NULL);
|
||||||
|
|
||||||
GstMessage *m = gst_message_new_element (GST_OBJECT (filter), s);
|
GstMessage *m = gst_message_new_element (GST_OBJECT (filter), s);
|
||||||
gst_element_post_message (GST_ELEMENT (filter), m);
|
gst_element_post_message (GST_ELEMENT (filter), m);
|
||||||
|
@ -299,24 +296,29 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf)
|
||||||
if (filter->display) {
|
if (filter->display) {
|
||||||
CvPoint center;
|
CvPoint center;
|
||||||
int radius;
|
int radius;
|
||||||
center.x = cvRound((r->x + r->width*0.5));
|
center.x = cvRound ((r->x + r->width * 0.5));
|
||||||
center.y = cvRound((r->y + r->height*0.5));
|
center.y = cvRound ((r->y + r->height * 0.5));
|
||||||
radius = cvRound((r->width + r->height)*0.25);
|
radius = cvRound ((r->width + r->height) * 0.25);
|
||||||
cvCircle(filter->cvImage, center, radius, CV_RGB(255, 32, 32), 3, 8, 0);
|
cvCircle (filter->cvImage, center, radius, CV_RGB (255, 32, 32), 3, 8,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_buffer_set_data(buf, filter->cvImage->imageData, filter->cvImage->imageSize);
|
gst_buffer_set_data (buf, filter->cvImage->imageData,
|
||||||
|
filter->cvImage->imageSize);
|
||||||
|
|
||||||
return gst_pad_push (filter->srcpad, buf);
|
return gst_pad_push (filter->srcpad, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void gst_facedetect_load_profile(Gstfacedetect * filter) {
|
static void
|
||||||
filter->cvCascade = (CvHaarClassifierCascade*)cvLoad(filter->profile, 0, 0, 0 );
|
gst_facedetect_load_profile (Gstfacedetect * filter)
|
||||||
|
{
|
||||||
|
filter->cvCascade =
|
||||||
|
(CvHaarClassifierCascade *) cvLoad (filter->profile, 0, 0, 0);
|
||||||
if (!filter->cvCascade) {
|
if (!filter->cvCascade) {
|
||||||
GST_WARNING ("Couldn't load Haar classifier cascade: %s.", filter->profile);
|
GST_WARNING ("Couldn't load Haar classifier cascade: %s.", filter->profile);
|
||||||
}
|
}
|
||||||
|
@ -332,7 +334,8 @@ gst_facedetect_plugin_init (GstPlugin * plugin)
|
||||||
{
|
{
|
||||||
/* debug category for fltering log messages */
|
/* debug category for fltering log messages */
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_facedetect_debug, "facedetect",
|
GST_DEBUG_CATEGORY_INIT (gst_facedetect_debug, "facedetect",
|
||||||
0, "Performs face detection on videos and images, providing detected positions via bus messages");
|
0,
|
||||||
|
"Performs face detection on videos and images, providing detected positions via bus messages");
|
||||||
|
|
||||||
return gst_element_register (plugin, "facedetect", GST_RANK_NONE,
|
return gst_element_register (plugin, "facedetect", GST_RANK_NONE,
|
||||||
GST_TYPE_FACEDETECT);
|
GST_TYPE_FACEDETECT);
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include <cv.h>
|
#include <cv.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/* #defines don't like whitespacey bits */
|
/* #defines don't like whitespacey bits */
|
||||||
#define GST_TYPE_FACEDETECT \
|
#define GST_TYPE_FACEDETECT \
|
||||||
(gst_facedetect_get_type())
|
(gst_facedetect_get_type())
|
||||||
|
@ -62,8 +61,7 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEDETECT))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEDETECT))
|
||||||
#define GST_IS_FACEDETECT_CLASS(klass) \
|
#define GST_IS_FACEDETECT_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEDETECT))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEDETECT))
|
||||||
|
typedef struct _Gstfacedetect Gstfacedetect;
|
||||||
typedef struct _Gstfacedetect Gstfacedetect;
|
|
||||||
typedef struct _GstfacedetectClass GstfacedetectClass;
|
typedef struct _GstfacedetectClass GstfacedetectClass;
|
||||||
|
|
||||||
struct _Gstfacedetect
|
struct _Gstfacedetect
|
||||||
|
@ -81,7 +79,7 @@ struct _Gstfacedetect
|
||||||
CvMemStorage *cvStorage;
|
CvMemStorage *cvStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstfacedetectClass
|
struct _GstfacedetectClass
|
||||||
{
|
{
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
@ -91,5 +89,4 @@ GType gst_facedetect_get_type (void);
|
||||||
gboolean gst_facedetect_plugin_init (GstPlugin * plugin);
|
gboolean gst_facedetect_plugin_init (GstPlugin * plugin);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_FACEDETECT_H__ */
|
#endif /* __GST_FACEDETECT_H__ */
|
||||||
|
|
|
@ -36,18 +36,18 @@ plugin_init (GstPlugin * plugin)
|
||||||
if (!gst_edgedetect_plugin_init (plugin))
|
if (!gst_edgedetect_plugin_init (plugin))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!gst_faceblur_plugin_init(plugin))
|
if (!gst_faceblur_plugin_init (plugin))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!gst_facedetect_plugin_init (plugin))
|
if (!gst_facedetect_plugin_init (plugin))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!gst_pyramidsegment_plugin_init (plugin))
|
if (!gst_pyramidsegment_plugin_init (plugin))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!gst_templatematch_plugin_init (plugin))
|
if (!gst_templatematch_plugin_init (plugin))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,12 +114,11 @@ static GstFlowReturn gst_pyramidsegment_chain (GstPad * pad, GstBuffer * buf);
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
static void
|
static void
|
||||||
gst_pyramidsegment_finalize (GObject * obj)
|
gst_pyramidsegment_finalize (GObject * obj)
|
||||||
{
|
{
|
||||||
Gstpyramidsegment *filter = GST_PYRAMIDSEGMENT(obj);
|
Gstpyramidsegment *filter = GST_PYRAMIDSEGMENT (obj);
|
||||||
|
|
||||||
if (filter->cvImage != NULL)
|
if (filter->cvImage != NULL) {
|
||||||
{
|
|
||||||
cvReleaseImage (&filter->cvImage);
|
cvReleaseImage (&filter->cvImage);
|
||||||
cvReleaseImage (&filter->cvSegmentedImage);
|
cvReleaseImage (&filter->cvSegmentedImage);
|
||||||
}
|
}
|
||||||
|
@ -133,11 +132,11 @@ gst_pyramidsegment_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
||||||
|
|
||||||
gst_element_class_set_details_simple(element_class,
|
gst_element_class_set_details_simple (element_class,
|
||||||
"pyramidsegment",
|
"pyramidsegment",
|
||||||
"Filter/Effect/Video",
|
"Filter/Effect/Video",
|
||||||
"Applies pyramid segmentation to a video or image.",
|
"Applies pyramid segmentation to a video or image.",
|
||||||
"Michael Sheldon <mike@mikeasoft.com>");
|
"Michael Sheldon <mike@mikeasoft.com>");
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
|
@ -165,16 +164,19 @@ gst_pyramidsegment_class_init (GstpyramidsegmentClass * klass)
|
||||||
FALSE, G_PARAM_READWRITE));
|
FALSE, G_PARAM_READWRITE));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
||||||
g_param_spec_double ("threshold1", "Threshold1", "Error threshold for establishing links",
|
g_param_spec_double ("threshold1", "Threshold1",
|
||||||
0, 1000, 50, G_PARAM_READWRITE));
|
"Error threshold for establishing links", 0, 1000, 50,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
||||||
g_param_spec_double ("threshold2", "Threshold2", "Error threshold for segment clustering",
|
g_param_spec_double ("threshold2", "Threshold2",
|
||||||
0, 1000, 60, G_PARAM_READWRITE));
|
"Error threshold for segment clustering", 0, 1000, 60,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_LEVEL,
|
g_object_class_install_property (gobject_class, PROP_LEVEL,
|
||||||
g_param_spec_int ("level", "Level", "Maximum level of the pyramid segmentation",
|
g_param_spec_int ("level", "Level",
|
||||||
0, 4, 4, G_PARAM_READWRITE));
|
"Maximum level of the pyramid segmentation", 0, 4, 4,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the new element
|
/* initialize the new element
|
||||||
|
@ -188,20 +190,21 @@ gst_pyramidsegment_init (Gstpyramidsegment * filter,
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pyramidsegment_set_caps));
|
GST_DEBUG_FUNCPTR (gst_pyramidsegment_set_caps));
|
||||||
gst_pad_set_getcaps_function (filter->sinkpad,
|
gst_pad_set_getcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
gst_pad_set_chain_function (filter->sinkpad,
|
gst_pad_set_chain_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pyramidsegment_chain));
|
GST_DEBUG_FUNCPTR (gst_pyramidsegment_chain));
|
||||||
|
|
||||||
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
gst_pad_set_getcaps_function (filter->srcpad,
|
gst_pad_set_getcaps_function (filter->srcpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
|
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||||
filter->storage = cvCreateMemStorage ( BLOCK_SIZE );
|
filter->storage = cvCreateMemStorage (BLOCK_SIZE);
|
||||||
filter->comp = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint), filter->storage);
|
filter->comp =
|
||||||
|
cvCreateSeq (0, sizeof (CvSeq), sizeof (CvPoint), filter->storage);
|
||||||
filter->silent = FALSE;
|
filter->silent = FALSE;
|
||||||
filter->threshold1 = 50.0;
|
filter->threshold1 = 50.0;
|
||||||
filter->threshold2 = 60.0;
|
filter->threshold2 = 60.0;
|
||||||
|
@ -274,8 +277,8 @@ gst_pyramidsegment_set_caps (GstPad * pad, GstCaps * caps)
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
gst_structure_get_int (structure, "width", &width);
|
gst_structure_get_int (structure, "width", &width);
|
||||||
gst_structure_get_int (structure, "height", &height);
|
gst_structure_get_int (structure, "height", &height);
|
||||||
|
|
||||||
filter->cvImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvImage = cvCreateImage (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
|
|
||||||
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
||||||
gst_object_unref (filter);
|
gst_object_unref (filter);
|
||||||
|
@ -294,11 +297,13 @@ gst_pyramidsegment_chain (GstPad * pad, GstBuffer * buf)
|
||||||
filter = GST_PYRAMIDSEGMENT (GST_OBJECT_PARENT (pad));
|
filter = GST_PYRAMIDSEGMENT (GST_OBJECT_PARENT (pad));
|
||||||
|
|
||||||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||||
filter->cvSegmentedImage = cvCloneImage(filter->cvImage);
|
filter->cvSegmentedImage = cvCloneImage (filter->cvImage);
|
||||||
|
|
||||||
cvPyrSegmentation(filter->cvImage, filter->cvSegmentedImage, filter->storage, &(filter->comp), filter->level, filter->threshold1, filter->threshold2);
|
cvPyrSegmentation (filter->cvImage, filter->cvSegmentedImage, filter->storage,
|
||||||
|
&(filter->comp), filter->level, filter->threshold1, filter->threshold2);
|
||||||
|
|
||||||
gst_buffer_set_data(buf, filter->cvSegmentedImage->imageData, filter->cvSegmentedImage->imageSize);
|
gst_buffer_set_data (buf, filter->cvSegmentedImage->imageData,
|
||||||
|
filter->cvSegmentedImage->imageSize);
|
||||||
|
|
||||||
return gst_pad_push (filter->srcpad, buf);
|
return gst_pad_push (filter->srcpad, buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include <cv.h>
|
#include <cv.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/* #defines don't like whitespacey bits */
|
/* #defines don't like whitespacey bits */
|
||||||
#define GST_TYPE_PYRAMIDSEGMENT \
|
#define GST_TYPE_PYRAMIDSEGMENT \
|
||||||
(gst_pyramidsegment_get_type())
|
(gst_pyramidsegment_get_type())
|
||||||
|
@ -62,8 +61,7 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PYRAMIDSEGMENT))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PYRAMIDSEGMENT))
|
||||||
#define GST_IS_PYRAMIDSEGMENT_CLASS(klass) \
|
#define GST_IS_PYRAMIDSEGMENT_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PYRAMIDSEGMENT))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PYRAMIDSEGMENT))
|
||||||
|
typedef struct _Gstpyramidsegment Gstpyramidsegment;
|
||||||
typedef struct _Gstpyramidsegment Gstpyramidsegment;
|
|
||||||
typedef struct _GstpyramidsegmentClass GstpyramidsegmentClass;
|
typedef struct _GstpyramidsegmentClass GstpyramidsegmentClass;
|
||||||
|
|
||||||
struct _Gstpyramidsegment
|
struct _Gstpyramidsegment
|
||||||
|
@ -81,11 +79,11 @@ struct _Gstpyramidsegment
|
||||||
CvSeq *comp;
|
CvSeq *comp;
|
||||||
|
|
||||||
double threshold1, threshold2;
|
double threshold1, threshold2;
|
||||||
|
|
||||||
int level;
|
int level;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstpyramidsegmentClass
|
struct _GstpyramidsegmentClass
|
||||||
{
|
{
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
@ -95,5 +93,4 @@ GType gst_pyramidsegment_get_type (void);
|
||||||
gboolean gst_pyramidsegment_plugin_init (GstPlugin * plugin);
|
gboolean gst_pyramidsegment_plugin_init (GstPlugin * plugin);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_PYRAMIDSEGMENT_H__ */
|
#endif /* __GST_PYRAMIDSEGMENT_H__ */
|
||||||
|
|
|
@ -73,94 +73,92 @@ GST_DEBUG_CATEGORY_STATIC (gst_templatematch_debug);
|
||||||
/* Filter signals and args */
|
/* Filter signals and args */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
/* FILL ME */
|
/* FILL ME */
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_METHOD,
|
PROP_METHOD,
|
||||||
PROP_TEMPLATE,
|
PROP_TEMPLATE,
|
||||||
PROP_DISPLAY,
|
PROP_DISPLAY,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* the capabilities of the inputs and outputs.
|
/* the capabilities of the inputs and outputs.
|
||||||
*/
|
*/
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (
|
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||||
"video/x-raw-rgb"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
GST_BOILERPLATE (GstTemplateMatch, gst_templatematch, GstElement,
|
GST_BOILERPLATE (GstTemplateMatch, gst_templatematch, GstElement,
|
||||||
GST_TYPE_ELEMENT);
|
GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
static void gst_templatematch_finalize (GObject * object);
|
static void gst_templatematch_finalize (GObject * object);
|
||||||
static void gst_templatematch_set_property (GObject * object, guint prop_id,
|
static void gst_templatematch_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_templatematch_get_property (GObject * object, guint prop_id,
|
static void gst_templatematch_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
static gboolean gst_templatematch_set_caps (GstPad * pad, GstCaps * caps);
|
static gboolean gst_templatematch_set_caps (GstPad * pad, GstCaps * caps);
|
||||||
static GstFlowReturn gst_templatematch_chain (GstPad * pad, GstBuffer * buf);
|
static GstFlowReturn gst_templatematch_chain (GstPad * pad, GstBuffer * buf);
|
||||||
|
|
||||||
static void gst_templatematch_load_template(GstTemplateMatch *filter);
|
static void gst_templatematch_load_template (GstTemplateMatch * filter);
|
||||||
static void gst_templatematch_match(IplImage *input, IplImage *template,
|
static void gst_templatematch_match (IplImage * input, IplImage * template,
|
||||||
IplImage *dist_image, double *best_res, CvPoint *best_pos, int method);
|
IplImage * dist_image, double *best_res, CvPoint * best_pos, int method);
|
||||||
|
|
||||||
/* GObject vmethod implementations */
|
/* GObject vmethod implementations */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_templatematch_base_init (gpointer gclass)
|
gst_templatematch_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
||||||
|
|
||||||
gst_element_class_set_details_simple(element_class,
|
gst_element_class_set_details_simple (element_class,
|
||||||
"templatematch",
|
"templatematch",
|
||||||
"Filter/Effect/Video",
|
"Filter/Effect/Video",
|
||||||
"Performs template matching on videos and images, providing detected positions via bus messages",
|
"Performs template matching on videos and images, providing detected positions via bus messages",
|
||||||
"Noam Lewis <jones.noamle@gmail.com>");
|
"Noam Lewis <jones.noamle@gmail.com>");
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&sink_factory));
|
gst_static_pad_template_get (&sink_factory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the templatematch's class */
|
/* initialize the templatematch's class */
|
||||||
static void
|
static void
|
||||||
gst_templatematch_class_init (GstTemplateMatchClass * klass)
|
gst_templatematch_class_init (GstTemplateMatchClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstElementClass *gstelement_class;
|
GstElementClass *gstelement_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
|
|
||||||
gobject_class->finalize = gst_templatematch_finalize;
|
gobject_class->finalize = gst_templatematch_finalize;
|
||||||
gobject_class->set_property = gst_templatematch_set_property;
|
gobject_class->set_property = gst_templatematch_set_property;
|
||||||
gobject_class->get_property = gst_templatematch_get_property;
|
gobject_class->get_property = gst_templatematch_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_METHOD,
|
g_object_class_install_property (gobject_class, PROP_METHOD,
|
||||||
g_param_spec_int ("method", "Method", "Specifies the way the template must be compared with image regions. 0=SQDIFF, 1=SQDIFF_NORMED, 2=CCOR, 3=CCOR_NORMED, 4=CCOEFF, 5=CCOEFF_NORMED.",
|
g_param_spec_int ("method", "Method",
|
||||||
0, 5, DEFAULT_METHOD, G_PARAM_READWRITE));
|
"Specifies the way the template must be compared with image regions. 0=SQDIFF, 1=SQDIFF_NORMED, 2=CCOR, 3=CCOR_NORMED, 4=CCOEFF, 5=CCOEFF_NORMED.",
|
||||||
g_object_class_install_property (gobject_class, PROP_TEMPLATE,
|
0, 5, DEFAULT_METHOD, G_PARAM_READWRITE));
|
||||||
g_param_spec_string ("template", "Template", "Filename of template image",
|
g_object_class_install_property (gobject_class, PROP_TEMPLATE,
|
||||||
NULL, G_PARAM_READWRITE));
|
g_param_spec_string ("template", "Template", "Filename of template image",
|
||||||
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
NULL, G_PARAM_READWRITE));
|
||||||
g_param_spec_boolean ("display", "Display", "Sets whether the detected template should be highlighted in the output",
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
||||||
TRUE, G_PARAM_READWRITE));
|
g_param_spec_boolean ("display", "Display",
|
||||||
|
"Sets whether the detected template should be highlighted in the output",
|
||||||
|
TRUE, G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize the new element
|
/* initialize the new element
|
||||||
|
@ -170,87 +168,93 @@ gst_templatematch_class_init (GstTemplateMatchClass * klass)
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
gst_templatematch_init (GstTemplateMatch * filter,
|
gst_templatematch_init (GstTemplateMatch * filter,
|
||||||
GstTemplateMatchClass * gclass)
|
GstTemplateMatchClass * gclass)
|
||||||
{
|
{
|
||||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_templatematch_set_caps));
|
GST_DEBUG_FUNCPTR (gst_templatematch_set_caps));
|
||||||
gst_pad_set_getcaps_function (filter->sinkpad,
|
gst_pad_set_getcaps_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
gst_pad_set_chain_function (filter->sinkpad,
|
gst_pad_set_chain_function (filter->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_templatematch_chain));
|
GST_DEBUG_FUNCPTR (gst_templatematch_chain));
|
||||||
|
|
||||||
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
gst_pad_set_getcaps_function (filter->srcpad,
|
gst_pad_set_getcaps_function (filter->srcpad,
|
||||||
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
|
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
||||||
|
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||||
filter->template = NULL;
|
filter->template = NULL;
|
||||||
filter->display = TRUE;
|
filter->display = TRUE;
|
||||||
filter->cvTemplateImage = NULL;
|
filter->cvTemplateImage = NULL;
|
||||||
filter->cvDistImage = NULL;
|
filter->cvDistImage = NULL;
|
||||||
filter->cvImage = NULL;
|
filter->cvImage = NULL;
|
||||||
filter->method = DEFAULT_METHOD;
|
filter->method = DEFAULT_METHOD;
|
||||||
gst_templatematch_load_template(filter);
|
gst_templatematch_load_template (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_templatematch_set_property (GObject * object, guint prop_id,
|
gst_templatematch_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstTemplateMatch *filter = GST_TEMPLATEMATCH (object);
|
GstTemplateMatch *filter = GST_TEMPLATEMATCH (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_METHOD:
|
case PROP_METHOD:
|
||||||
switch (g_value_get_int (value)) {
|
switch (g_value_get_int (value)) {
|
||||||
case 0:
|
case 0:
|
||||||
filter->method = CV_TM_SQDIFF; break;
|
filter->method = CV_TM_SQDIFF;
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
filter->method = CV_TM_SQDIFF_NORMED; break;
|
filter->method = CV_TM_SQDIFF_NORMED;
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
filter->method = CV_TM_CCORR; break;
|
filter->method = CV_TM_CCORR;
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
filter->method = CV_TM_CCORR_NORMED; break;
|
filter->method = CV_TM_CCORR_NORMED;
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
filter->method = CV_TM_CCOEFF; break;
|
filter->method = CV_TM_CCOEFF;
|
||||||
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
filter->method = CV_TM_CCOEFF_NORMED; break;
|
filter->method = CV_TM_CCOEFF_NORMED;
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
case PROP_TEMPLATE:
|
case PROP_TEMPLATE:
|
||||||
filter->template = g_value_get_string (value);
|
filter->template = g_value_get_string (value);
|
||||||
gst_templatematch_load_template(filter);
|
gst_templatematch_load_template (filter);
|
||||||
break;
|
break;
|
||||||
case PROP_DISPLAY:
|
case PROP_DISPLAY:
|
||||||
filter->display = g_value_get_boolean (value);
|
filter->display = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_templatematch_get_property (GObject * object, guint prop_id,
|
gst_templatematch_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstTemplateMatch *filter = GST_TEMPLATEMATCH (object);
|
GstTemplateMatch *filter = GST_TEMPLATEMATCH (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_METHOD:
|
case PROP_METHOD:
|
||||||
g_value_set_int(value, filter->method);
|
g_value_set_int (value, filter->method);
|
||||||
break;
|
break;
|
||||||
case PROP_TEMPLATE:
|
case PROP_TEMPLATE:
|
||||||
g_value_set_string (value, filter->template);
|
g_value_set_string (value, filter->template);
|
||||||
break;
|
break;
|
||||||
case PROP_DISPLAY:
|
case PROP_DISPLAY:
|
||||||
g_value_set_boolean (value, filter->display);
|
g_value_set_boolean (value, filter->display);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GstElement vmethod implementations */
|
/* GstElement vmethod implementations */
|
||||||
|
@ -259,38 +263,40 @@ gst_templatematch_get_property (GObject * object, guint prop_id,
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_templatematch_set_caps (GstPad * pad, GstCaps * caps)
|
gst_templatematch_set_caps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstTemplateMatch *filter;
|
GstTemplateMatch *filter;
|
||||||
GstPad *otherpad;
|
GstPad *otherpad;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
|
|
||||||
filter = GST_TEMPLATEMATCH (gst_pad_get_parent (pad));
|
filter = GST_TEMPLATEMATCH (gst_pad_get_parent (pad));
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
gst_structure_get_int (structure, "width", &width);
|
gst_structure_get_int (structure, "width", &width);
|
||||||
gst_structure_get_int (structure, "height", &height);
|
gst_structure_get_int (structure, "height", &height);
|
||||||
|
|
||||||
filter->cvImage = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
|
filter->cvImage =
|
||||||
|
cvCreateImageHeader (cvSize (width, height), IPL_DEPTH_8U, 3);
|
||||||
|
|
||||||
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
|
||||||
gst_object_unref (filter);
|
gst_object_unref (filter);
|
||||||
|
|
||||||
return gst_pad_set_caps (otherpad, caps);
|
return gst_pad_set_caps (otherpad, caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gst_templatematch_finalize (GObject * object)
|
static void
|
||||||
|
gst_templatematch_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstTemplateMatch *filter;
|
GstTemplateMatch *filter;
|
||||||
filter = GST_TEMPLATEMATCH (object);
|
filter = GST_TEMPLATEMATCH (object);
|
||||||
|
|
||||||
if (filter->cvImage) {
|
if (filter->cvImage) {
|
||||||
cvReleaseImageHeader(&filter->cvImage);
|
cvReleaseImageHeader (&filter->cvImage);
|
||||||
}
|
}
|
||||||
if (filter->cvDistImage) {
|
if (filter->cvDistImage) {
|
||||||
cvReleaseImage(&filter->cvDistImage);
|
cvReleaseImage (&filter->cvDistImage);
|
||||||
}
|
}
|
||||||
if (filter->cvTemplateImage) {
|
if (filter->cvTemplateImage) {
|
||||||
cvReleaseImage(&filter->cvTemplateImage);
|
cvReleaseImage (&filter->cvTemplateImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* chain function
|
/* chain function
|
||||||
|
@ -299,88 +305,94 @@ static void gst_templatematch_finalize (GObject * object)
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_templatematch_chain (GstPad * pad, GstBuffer * buf)
|
gst_templatematch_chain (GstPad * pad, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstTemplateMatch *filter;
|
GstTemplateMatch *filter;
|
||||||
CvPoint best_pos;
|
CvPoint best_pos;
|
||||||
double best_res;
|
double best_res;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
filter = GST_TEMPLATEMATCH (GST_OBJECT_PARENT (pad));
|
filter = GST_TEMPLATEMATCH (GST_OBJECT_PARENT (pad));
|
||||||
buf = gst_buffer_make_writable(buf);
|
buf = gst_buffer_make_writable (buf);
|
||||||
if ((!filter) || (!buf) || filter->template == NULL) {
|
if ((!filter) || (!buf) || filter->template == NULL) {
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||||
|
|
||||||
|
|
||||||
|
if (!filter->cvDistImage) {
|
||||||
|
filter->cvDistImage =
|
||||||
|
cvCreateImage (cvSize (filter->cvImage->width -
|
||||||
|
filter->cvTemplateImage->width + 1,
|
||||||
|
filter->cvImage->height - filter->cvTemplateImage->height + 1),
|
||||||
|
IPL_DEPTH_32F, 1);
|
||||||
if (!filter->cvDistImage) {
|
if (!filter->cvDistImage) {
|
||||||
filter->cvDistImage = cvCreateImage( cvSize(filter->cvImage->width - filter->cvTemplateImage->width + 1,
|
GST_WARNING ("Couldn't create dist image.");
|
||||||
filter->cvImage->height - filter->cvTemplateImage->height + 1),
|
|
||||||
IPL_DEPTH_32F, 1);
|
|
||||||
if (!filter->cvDistImage) {
|
|
||||||
GST_WARNING ("Couldn't create dist image.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (filter->cvTemplateImage) {
|
}
|
||||||
gst_templatematch_match(filter->cvImage, filter->cvTemplateImage,
|
if (filter->cvTemplateImage) {
|
||||||
filter->cvDistImage, &best_res, &best_pos, filter->method);
|
gst_templatematch_match (filter->cvImage, filter->cvTemplateImage,
|
||||||
|
filter->cvDistImage, &best_res, &best_pos, filter->method);
|
||||||
GstStructure *s = gst_structure_new ("template_match",
|
|
||||||
"x", G_TYPE_UINT, best_pos.x,
|
|
||||||
"y", G_TYPE_UINT, best_pos.y,
|
|
||||||
"width", G_TYPE_UINT, filter->cvTemplateImage->width,
|
|
||||||
"height", G_TYPE_UINT, filter->cvTemplateImage->height,
|
|
||||||
"result", G_TYPE_DOUBLE, best_res,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
GstMessage *m = gst_message_new_element (GST_OBJECT (filter), s);
|
GstStructure *s = gst_structure_new ("template_match",
|
||||||
gst_element_post_message (GST_ELEMENT (filter), m);
|
"x", G_TYPE_UINT, best_pos.x,
|
||||||
|
"y", G_TYPE_UINT, best_pos.y,
|
||||||
|
"width", G_TYPE_UINT, filter->cvTemplateImage->width,
|
||||||
|
"height", G_TYPE_UINT, filter->cvTemplateImage->height,
|
||||||
|
"result", G_TYPE_DOUBLE, best_res,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (filter->display) {
|
GstMessage *m = gst_message_new_element (GST_OBJECT (filter), s);
|
||||||
CvPoint corner = best_pos;
|
gst_element_post_message (GST_ELEMENT (filter), m);
|
||||||
corner.x += filter->cvTemplateImage->width;
|
|
||||||
corner.y += filter->cvTemplateImage->height;
|
|
||||||
cvRectangle(filter->cvImage, best_pos, corner, CV_RGB(255, 32, 32), 3, 8, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (filter->display) {
|
||||||
|
CvPoint corner = best_pos;
|
||||||
|
corner.x += filter->cvTemplateImage->width;
|
||||||
|
corner.y += filter->cvTemplateImage->height;
|
||||||
|
cvRectangle (filter->cvImage, best_pos, corner, CV_RGB (255, 32, 32), 3,
|
||||||
|
8, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
gst_buffer_set_data(buf, filter->cvImage->imageData, filter->cvImage->imageSize);
|
|
||||||
|
|
||||||
return gst_pad_push (filter->srcpad, buf);
|
|
||||||
|
gst_buffer_set_data (buf, filter->cvImage->imageData,
|
||||||
|
filter->cvImage->imageSize);
|
||||||
|
|
||||||
|
return gst_pad_push (filter->srcpad, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void gst_templatematch_match(IplImage *input, IplImage *template,
|
static void
|
||||||
IplImage *dist_image, double *best_res, CvPoint *best_pos, int method)
|
gst_templatematch_match (IplImage * input, IplImage * template,
|
||||||
|
IplImage * dist_image, double *best_res, CvPoint * best_pos, int method)
|
||||||
{
|
{
|
||||||
double dist_min = 0, dist_max = 0;
|
double dist_min = 0, dist_max = 0;
|
||||||
CvPoint min_pos, max_pos;
|
CvPoint min_pos, max_pos;
|
||||||
cvMatchTemplate(input, template, dist_image, method);
|
cvMatchTemplate (input, template, dist_image, method);
|
||||||
cvMinMaxLoc(dist_image, &dist_min, &dist_max, &min_pos, &max_pos, NULL);
|
cvMinMaxLoc (dist_image, &dist_min, &dist_max, &min_pos, &max_pos, NULL);
|
||||||
if ((CV_TM_SQDIFF_NORMED == method) || (CV_TM_SQDIFF == method))
|
if ((CV_TM_SQDIFF_NORMED == method) || (CV_TM_SQDIFF == method)) {
|
||||||
{
|
*best_res = dist_min;
|
||||||
*best_res = dist_min;
|
*best_pos = min_pos;
|
||||||
*best_pos = min_pos;
|
if (CV_TM_SQDIFF_NORMED == method) {
|
||||||
if (CV_TM_SQDIFF_NORMED == method) {
|
*best_res = 1 - *best_res;
|
||||||
*best_res = 1-*best_res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*best_res = dist_max;
|
|
||||||
*best_pos = max_pos;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
*best_res = dist_max;
|
||||||
|
*best_pos = max_pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void gst_templatematch_load_template(GstTemplateMatch *filter) {
|
static void
|
||||||
if (filter->template) {
|
gst_templatematch_load_template (GstTemplateMatch * filter)
|
||||||
filter->cvTemplateImage = cvLoadImage(filter->template, CV_LOAD_IMAGE_COLOR);
|
{
|
||||||
if (!filter->cvTemplateImage) {
|
if (filter->template) {
|
||||||
GST_WARNING ("Couldn't load template image: %s.", filter->template);
|
filter->cvTemplateImage =
|
||||||
}
|
cvLoadImage (filter->template, CV_LOAD_IMAGE_COLOR);
|
||||||
|
if (!filter->cvTemplateImage) {
|
||||||
|
GST_WARNING ("Couldn't load template image: %s.", filter->template);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -388,14 +400,14 @@ static void gst_templatematch_load_template(GstTemplateMatch *filter) {
|
||||||
* initialize the plug-in itself
|
* initialize the plug-in itself
|
||||||
* register the element factories and other features
|
* register the element factories and other features
|
||||||
*/
|
*/
|
||||||
gboolean gst_templatematch_plugin_init (GstPlugin * templatematch)
|
gboolean
|
||||||
|
gst_templatematch_plugin_init (GstPlugin * templatematch)
|
||||||
{
|
{
|
||||||
/* debug category for fltering log messages */
|
/* debug category for fltering log messages */
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_templatematch_debug, "templatematch",
|
GST_DEBUG_CATEGORY_INIT (gst_templatematch_debug, "templatematch",
|
||||||
0, "Performs template matching on videos and images, providing detected positions via bus messages");
|
0,
|
||||||
|
"Performs template matching on videos and images, providing detected positions via bus messages");
|
||||||
|
|
||||||
return gst_element_register (templatematch, "templatematch", GST_RANK_NONE,
|
return gst_element_register (templatematch, "templatematch", GST_RANK_NONE,
|
||||||
GST_TYPE_TEMPLATEMATCH);
|
GST_TYPE_TEMPLATEMATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
#include <opencv/highgui.h>
|
#include <opencv/highgui.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/* #defines don't like whitespacey bits */
|
/* #defines don't like whitespacey bits */
|
||||||
#define GST_TYPE_TEMPLATEMATCH \
|
#define GST_TYPE_TEMPLATEMATCH \
|
||||||
(gst_templatematch_get_type())
|
(gst_templatematch_get_type())
|
||||||
|
@ -63,8 +62,7 @@ G_BEGIN_DECLS
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEMPLATEMATCH))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEMPLATEMATCH))
|
||||||
#define GST_IS_TEMPLATEMATCH_CLASS(klass) \
|
#define GST_IS_TEMPLATEMATCH_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEMPLATEMATCH))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEMPLATEMATCH))
|
||||||
|
typedef struct _GstTemplateMatch GstTemplateMatch;
|
||||||
typedef struct _GstTemplateMatch GstTemplateMatch;
|
|
||||||
typedef struct _GstTemplateMatchClass GstTemplateMatchClass;
|
typedef struct _GstTemplateMatchClass GstTemplateMatchClass;
|
||||||
|
|
||||||
struct _GstTemplateMatch
|
struct _GstTemplateMatch
|
||||||
|
@ -73,15 +71,15 @@ struct _GstTemplateMatch
|
||||||
|
|
||||||
GstPad *sinkpad, *srcpad;
|
GstPad *sinkpad, *srcpad;
|
||||||
|
|
||||||
gint method;
|
gint method;
|
||||||
gboolean display;
|
gboolean display;
|
||||||
|
|
||||||
gchar *template;
|
gchar *template;
|
||||||
|
|
||||||
IplImage *cvImage, *cvGray, *cvTemplateImage, *cvDistImage;
|
IplImage *cvImage, *cvGray, *cvTemplateImage, *cvDistImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstTemplateMatchClass
|
struct _GstTemplateMatchClass
|
||||||
{
|
{
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
@ -91,5 +89,4 @@ GType gst_templatematch_get_type (void);
|
||||||
gboolean gst_templatematch_plugin_init (GstPlugin * templatematch);
|
gboolean gst_templatematch_plugin_init (GstPlugin * templatematch);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_TEMPLATEMATCH_H__ */
|
#endif /* __GST_TEMPLATEMATCH_H__ */
|
||||||
|
|
Loading…
Reference in a new issue