mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +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",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (Gstedgedetect, gst_edgedetect, GstElement,
|
||||
GST_TYPE_ELEMENT);
|
||||
GST_BOILERPLATE (Gstedgedetect, gst_edgedetect, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static void gst_edgedetect_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
|
@ -120,8 +115,7 @@ gst_edgedetect_finalize (GObject * obj)
|
|||
{
|
||||
Gstedgedetect *filter = GST_EDGEDETECT (obj);
|
||||
|
||||
if (filter->cvImage != NULL)
|
||||
{
|
||||
if (filter->cvImage != NULL) {
|
||||
cvReleaseImage (&filter->cvImage);
|
||||
cvReleaseImage (&filter->cvCEdge);
|
||||
cvReleaseImage (&filter->cvGray);
|
||||
|
@ -165,17 +159,21 @@ gst_edgedetect_class_init (GstedgedetectClass * klass)
|
|||
gobject_class->get_property = gst_edgedetect_get_property;
|
||||
|
||||
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));
|
||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
||||
g_param_spec_int ("threshold1", "Threshold1", "Threshold value for canny edge detection",
|
||||
0, 1000, 50, G_PARAM_READWRITE));
|
||||
g_param_spec_int ("threshold1", "Threshold1",
|
||||
"Threshold value for canny edge detection", 0, 1000, 50,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
||||
g_param_spec_int ("threshold2", "Threshold2", "Second threshold value for canny edge detection",
|
||||
0, 1000, 150, G_PARAM_READWRITE));
|
||||
g_param_spec_int ("threshold2", "Threshold2",
|
||||
"Second threshold value for canny edge detection", 0, 1000, 150,
|
||||
G_PARAM_READWRITE));
|
||||
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",
|
||||
3, 7, 3, G_PARAM_READWRITE));
|
||||
g_param_spec_int ("aperture", "Aperture",
|
||||
"Aperture size for Sobel operator (Must be either 3, 5 or 7", 3, 7, 3,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
/* initialize the new element
|
||||
|
@ -184,8 +182,7 @@ gst_edgedetect_class_init (GstedgedetectClass * klass)
|
|||
* initialize instance structure
|
||||
*/
|
||||
static void
|
||||
gst_edgedetect_init (Gstedgedetect * filter,
|
||||
GstedgedetectClass * gclass)
|
||||
gst_edgedetect_init (Gstedgedetect * filter, GstedgedetectClass * gclass)
|
||||
{
|
||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||
|
@ -299,7 +296,8 @@ gst_edgedetect_chain (GstPad * pad, GstBuffer * buf)
|
|||
cvCvtColor (filter->cvImage, filter->cvGray, CV_RGB2GRAY);
|
||||
cvSmooth (filter->cvGray, filter->cvEdge, CV_BLUR, 3, 3, 0, 0);
|
||||
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);
|
||||
if (filter->mask) {
|
||||
|
@ -307,7 +305,8 @@ gst_edgedetect_chain (GstPad * pad, GstBuffer * buf)
|
|||
} else {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include <cv.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* #defines don't like whitespacey bits */
|
||||
#define GST_TYPE_EDGEDETECT \
|
||||
(gst_edgedetect_get_type())
|
||||
|
@ -62,7 +61,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDGEDETECT))
|
||||
#define GST_IS_EDGEDETECT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDGEDETECT))
|
||||
|
||||
typedef struct _Gstedgedetect Gstedgedetect;
|
||||
typedef struct _GstedgedetectClass GstedgedetectClass;
|
||||
|
||||
|
@ -89,5 +87,4 @@ GType gst_edgedetect_get_type (void);
|
|||
gboolean gst_edgedetect_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_EDGEDETECT_H__ */
|
||||
|
|
|
@ -87,21 +87,16 @@ enum
|
|||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (Gstfaceblur, gst_faceblur, GstElement,
|
||||
GST_TYPE_ELEMENT);
|
||||
GST_BOILERPLATE (Gstfaceblur, gst_faceblur, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static void gst_faceblur_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
|
@ -119,8 +114,7 @@ gst_faceblur_finalize (GObject * obj)
|
|||
{
|
||||
Gstfaceblur *filter = GST_FACEBLUR (obj);
|
||||
|
||||
if (filter->cvImage)
|
||||
{
|
||||
if (filter->cvImage) {
|
||||
cvReleaseImage (&filter->cvImage);
|
||||
cvReleaseImage (&filter->cvGray);
|
||||
}
|
||||
|
@ -163,7 +157,8 @@ gst_faceblur_class_init (GstfaceblurClass * klass)
|
|||
gobject_class->get_property = gst_faceblur_get_property;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -173,8 +168,7 @@ gst_faceblur_class_init (GstfaceblurClass * klass)
|
|||
* initialize instance structure
|
||||
*/
|
||||
static void
|
||||
gst_faceblur_init (Gstfaceblur * filter,
|
||||
GstfaceblurClass * gclass)
|
||||
gst_faceblur_init (Gstfaceblur * filter, GstfaceblurClass * gclass)
|
||||
{
|
||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||
|
@ -271,7 +265,9 @@ gst_faceblur_chain (GstPad * pad, GstBuffer * buf)
|
|||
cvClearMemStorage (filter->cvStorage);
|
||||
|
||||
if (filter->cvCascade) {
|
||||
faces = cvHaarDetectObjects(filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize(30, 30));
|
||||
faces =
|
||||
cvHaarDetectObjects (filter->cvGray, filter->cvCascade,
|
||||
filter->cvStorage, 1.1, 2, 0, cvSize (30, 30));
|
||||
|
||||
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
||||
CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
|
||||
|
@ -283,14 +279,18 @@ gst_faceblur_chain (GstPad * pad, GstBuffer * buf)
|
|||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void gst_faceblur_load_profile(Gstfaceblur * filter) {
|
||||
filter->cvCascade = (CvHaarClassifierCascade*)cvLoad(filter->profile, 0, 0, 0 );
|
||||
static void
|
||||
gst_faceblur_load_profile (Gstfaceblur * filter)
|
||||
{
|
||||
filter->cvCascade =
|
||||
(CvHaarClassifierCascade *) cvLoad (filter->profile, 0, 0, 0);
|
||||
if (!filter->cvCascade) {
|
||||
GST_WARNING ("Couldn't load Haar classifier cascade: %s.", filter->profile);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include <cv.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* #defines don't like whitespacey bits */
|
||||
#define GST_TYPE_FACEBLUR \
|
||||
(gst_faceblur_get_type())
|
||||
|
@ -62,7 +61,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEBLUR))
|
||||
#define GST_IS_FACEBLUR_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEBLUR))
|
||||
|
||||
typedef struct _Gstfaceblur Gstfaceblur;
|
||||
typedef struct _GstfaceblurClass GstfaceblurClass;
|
||||
|
||||
|
@ -91,5 +89,4 @@ GType gst_faceblur_get_type (void);
|
|||
gboolean gst_faceblur_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_FACEBLUR_H__ */
|
||||
|
|
|
@ -88,21 +88,16 @@ enum
|
|||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (Gstfacedetect, gst_facedetect, GstElement,
|
||||
GST_TYPE_ELEMENT);
|
||||
GST_BOILERPLATE (Gstfacedetect, gst_facedetect, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static void gst_facedetect_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
|
@ -120,8 +115,7 @@ gst_facedetect_finalize (GObject * obj)
|
|||
{
|
||||
Gstfacedetect *filter = GST_FACEDETECT (obj);
|
||||
|
||||
if (filter->cvImage)
|
||||
{
|
||||
if (filter->cvImage) {
|
||||
cvReleaseImage (&filter->cvImage);
|
||||
cvReleaseImage (&filter->cvGray);
|
||||
}
|
||||
|
@ -164,10 +158,12 @@ gst_facedetect_class_init (GstfacedetectClass * klass)
|
|||
gobject_class->get_property = gst_facedetect_get_property;
|
||||
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -177,8 +173,7 @@ gst_facedetect_class_init (GstfacedetectClass * klass)
|
|||
* initialize instance structure
|
||||
*/
|
||||
static void
|
||||
gst_facedetect_init (Gstfacedetect * filter,
|
||||
GstfacedetectClass * gclass)
|
||||
gst_facedetect_init (Gstfacedetect * filter, GstfacedetectClass * gclass)
|
||||
{
|
||||
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||
gst_pad_set_setcaps_function (filter->sinkpad,
|
||||
|
@ -282,7 +277,9 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf)
|
|||
cvClearMemStorage (filter->cvStorage);
|
||||
|
||||
if (filter->cvCascade) {
|
||||
faces = cvHaarDetectObjects(filter->cvGray, filter->cvCascade, filter->cvStorage, 1.1, 2, 0, cvSize(30, 30));
|
||||
faces =
|
||||
cvHaarDetectObjects (filter->cvGray, filter->cvCascade,
|
||||
filter->cvStorage, 1.1, 2, 0, cvSize (30, 30));
|
||||
|
||||
for (i = 0; i < (faces ? faces->total : 0); i++) {
|
||||
CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
|
||||
|
@ -302,21 +299,26 @@ gst_facedetect_chain (GstPad * pad, GstBuffer * buf)
|
|||
center.x = cvRound ((r->x + r->width * 0.5));
|
||||
center.y = cvRound ((r->y + r->height * 0.5));
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static void gst_facedetect_load_profile(Gstfacedetect * filter) {
|
||||
filter->cvCascade = (CvHaarClassifierCascade*)cvLoad(filter->profile, 0, 0, 0 );
|
||||
static void
|
||||
gst_facedetect_load_profile (Gstfacedetect * filter)
|
||||
{
|
||||
filter->cvCascade =
|
||||
(CvHaarClassifierCascade *) cvLoad (filter->profile, 0, 0, 0);
|
||||
if (!filter->cvCascade) {
|
||||
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 */
|
||||
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,
|
||||
GST_TYPE_FACEDETECT);
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include <cv.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* #defines don't like whitespacey bits */
|
||||
#define GST_TYPE_FACEDETECT \
|
||||
(gst_facedetect_get_type())
|
||||
|
@ -62,7 +61,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACEDETECT))
|
||||
#define GST_IS_FACEDETECT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACEDETECT))
|
||||
|
||||
typedef struct _Gstfacedetect Gstfacedetect;
|
||||
typedef struct _GstfacedetectClass GstfacedetectClass;
|
||||
|
||||
|
@ -91,5 +89,4 @@ GType gst_facedetect_get_type (void);
|
|||
gboolean gst_facedetect_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_FACEDETECT_H__ */
|
||||
|
|
|
@ -118,8 +118,7 @@ gst_pyramidsegment_finalize (GObject * obj)
|
|||
{
|
||||
Gstpyramidsegment *filter = GST_PYRAMIDSEGMENT (obj);
|
||||
|
||||
if (filter->cvImage != NULL)
|
||||
{
|
||||
if (filter->cvImage != NULL) {
|
||||
cvReleaseImage (&filter->cvImage);
|
||||
cvReleaseImage (&filter->cvSegmentedImage);
|
||||
}
|
||||
|
@ -165,16 +164,19 @@ gst_pyramidsegment_class_init (GstpyramidsegmentClass * klass)
|
|||
FALSE, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD1,
|
||||
g_param_spec_double ("threshold1", "Threshold1", "Error threshold for establishing links",
|
||||
0, 1000, 50, G_PARAM_READWRITE));
|
||||
g_param_spec_double ("threshold1", "Threshold1",
|
||||
"Error threshold for establishing links", 0, 1000, 50,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD2,
|
||||
g_param_spec_double ("threshold2", "Threshold2", "Error threshold for segment clustering",
|
||||
0, 1000, 60, G_PARAM_READWRITE));
|
||||
g_param_spec_double ("threshold2", "Threshold2",
|
||||
"Error threshold for segment clustering", 0, 1000, 60,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_LEVEL,
|
||||
g_param_spec_int ("level", "Level", "Maximum level of the pyramid segmentation",
|
||||
0, 4, 4, G_PARAM_READWRITE));
|
||||
g_param_spec_int ("level", "Level",
|
||||
"Maximum level of the pyramid segmentation", 0, 4, 4,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
/* initialize the new element
|
||||
|
@ -201,7 +203,8 @@ gst_pyramidsegment_init (Gstpyramidsegment * filter,
|
|||
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
||||
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
||||
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->threshold1 = 50.0;
|
||||
filter->threshold2 = 60.0;
|
||||
|
@ -296,9 +299,11 @@ gst_pyramidsegment_chain (GstPad * pad, GstBuffer * buf)
|
|||
filter->cvImage->imageData = (char *) GST_BUFFER_DATA (buf);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include <cv.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* #defines don't like whitespacey bits */
|
||||
#define GST_TYPE_PYRAMIDSEGMENT \
|
||||
(gst_pyramidsegment_get_type())
|
||||
|
@ -62,7 +61,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PYRAMIDSEGMENT))
|
||||
#define GST_IS_PYRAMIDSEGMENT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PYRAMIDSEGMENT))
|
||||
|
||||
typedef struct _Gstpyramidsegment Gstpyramidsegment;
|
||||
typedef struct _GstpyramidsegmentClass GstpyramidsegmentClass;
|
||||
|
||||
|
@ -95,5 +93,4 @@ GType gst_pyramidsegment_get_type (void);
|
|||
gboolean gst_pyramidsegment_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_PYRAMIDSEGMENT_H__ */
|
||||
|
|
|
@ -90,17 +90,13 @@ enum
|
|||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (
|
||||
"video/x-raw-rgb"
|
||||
)
|
||||
GST_STATIC_CAPS ("video/x-raw-rgb")
|
||||
);
|
||||
|
||||
GST_BOILERPLATE (GstTemplateMatch, gst_templatematch, GstElement,
|
||||
|
@ -153,13 +149,15 @@ gst_templatematch_class_init (GstTemplateMatchClass * klass)
|
|||
gobject_class->get_property = gst_templatematch_get_property;
|
||||
|
||||
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",
|
||||
"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.",
|
||||
0, 5, DEFAULT_METHOD, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class, PROP_TEMPLATE,
|
||||
g_param_spec_string ("template", "Template", "Filename of template image",
|
||||
NULL, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
||||
g_param_spec_boolean ("display", "Display", "Sets whether the detected template should be highlighted in the output",
|
||||
g_param_spec_boolean ("display", "Display",
|
||||
"Sets whether the detected template should be highlighted in the output",
|
||||
TRUE, G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
|
@ -205,17 +203,23 @@ gst_templatematch_set_property (GObject * object, guint prop_id,
|
|||
case PROP_METHOD:
|
||||
switch (g_value_get_int (value)) {
|
||||
case 0:
|
||||
filter->method = CV_TM_SQDIFF; break;
|
||||
filter->method = CV_TM_SQDIFF;
|
||||
break;
|
||||
case 1:
|
||||
filter->method = CV_TM_SQDIFF_NORMED; break;
|
||||
filter->method = CV_TM_SQDIFF_NORMED;
|
||||
break;
|
||||
case 2:
|
||||
filter->method = CV_TM_CCORR; break;
|
||||
filter->method = CV_TM_CCORR;
|
||||
break;
|
||||
case 3:
|
||||
filter->method = CV_TM_CCORR_NORMED; break;
|
||||
filter->method = CV_TM_CCORR_NORMED;
|
||||
break;
|
||||
case 4:
|
||||
filter->method = CV_TM_CCOEFF; break;
|
||||
filter->method = CV_TM_CCOEFF;
|
||||
break;
|
||||
case 5:
|
||||
filter->method = CV_TM_CCOEFF_NORMED; break;
|
||||
filter->method = CV_TM_CCOEFF_NORMED;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PROP_TEMPLATE:
|
||||
|
@ -269,7 +273,8 @@ gst_templatematch_set_caps (GstPad * pad, GstCaps * caps)
|
|||
gst_structure_get_int (structure, "width", &width);
|
||||
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;
|
||||
gst_object_unref (filter);
|
||||
|
@ -277,7 +282,8 @@ gst_templatematch_set_caps (GstPad * pad, GstCaps * caps)
|
|||
return gst_pad_set_caps (otherpad, caps);
|
||||
}
|
||||
|
||||
static void gst_templatematch_finalize (GObject * object)
|
||||
static void
|
||||
gst_templatematch_finalize (GObject * object)
|
||||
{
|
||||
GstTemplateMatch *filter;
|
||||
filter = GST_TEMPLATEMATCH (object);
|
||||
|
@ -313,7 +319,9 @@ gst_templatematch_chain (GstPad * pad, GstBuffer * buf)
|
|||
|
||||
|
||||
if (!filter->cvDistImage) {
|
||||
filter->cvDistImage = cvCreateImage( cvSize(filter->cvImage->width - filter->cvTemplateImage->width + 1,
|
||||
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) {
|
||||
|
@ -339,44 +347,48 @@ gst_templatematch_chain (GstPad * pad, GstBuffer * buf)
|
|||
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);
|
||||
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);
|
||||
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
|
||||
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;
|
||||
CvPoint min_pos, max_pos;
|
||||
cvMatchTemplate (input, template, dist_image, method);
|
||||
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_pos = min_pos;
|
||||
if (CV_TM_SQDIFF_NORMED == method) {
|
||||
*best_res = 1 - *best_res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*best_res = dist_max;
|
||||
*best_pos = max_pos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void gst_templatematch_load_template(GstTemplateMatch *filter) {
|
||||
static void
|
||||
gst_templatematch_load_template (GstTemplateMatch * filter)
|
||||
{
|
||||
if (filter->template) {
|
||||
filter->cvTemplateImage = cvLoadImage(filter->template, CV_LOAD_IMAGE_COLOR);
|
||||
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
|
||||
* 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 */
|
||||
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,
|
||||
GST_TYPE_TEMPLATEMATCH);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include <opencv/highgui.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* #defines don't like whitespacey bits */
|
||||
#define GST_TYPE_TEMPLATEMATCH \
|
||||
(gst_templatematch_get_type())
|
||||
|
@ -63,7 +62,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEMPLATEMATCH))
|
||||
#define GST_IS_TEMPLATEMATCH_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEMPLATEMATCH))
|
||||
|
||||
typedef struct _GstTemplateMatch GstTemplateMatch;
|
||||
typedef struct _GstTemplateMatchClass GstTemplateMatchClass;
|
||||
|
||||
|
@ -91,5 +89,4 @@ GType gst_templatematch_get_type (void);
|
|||
gboolean gst_templatematch_plugin_init (GstPlugin * templatematch);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_TEMPLATEMATCH_H__ */
|
||||
|
|
Loading…
Reference in a new issue