Skip to content

Commit d5e94da

Browse files
123vivekrGStreamer Marge Bot
authored and
GStreamer Marge Bot
committed
opencv: cvtracker: add draw property
This property controls the drawing of rectangle around the tracked object. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2454>
1 parent d28f119 commit d5e94da

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/opencv/gstcvtracker.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum
7878
PROP_INITIAL_WIDTH,
7979
PROP_INITIAL_HEIGHT,
8080
PROP_ALGORITHM,
81+
PROP_DRAW,
8182
};
8283

8384
#define GST_OPENCV_TRACKER_ALGORITHM (tracker_algorithm_get_type ())
@@ -207,6 +208,11 @@ gst_cvtracker_class_init (GstCVTrackerClass * klass)
207208
GST_OPENCV_TRACKER_ALGORITHM_MEDIANFLOW,
208209
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
209210

211+
g_object_class_install_property (gobject_class, PROP_DRAW,
212+
g_param_spec_boolean ("draw-rect", "Display",
213+
"Draw rectangle around tracked object",
214+
TRUE, (GParamFlags) G_PARAM_READWRITE));
215+
210216
gst_element_class_set_static_metadata (element_class,
211217
"cvtracker",
212218
"Filter/Effect/Video",
@@ -233,6 +239,7 @@ gst_cvtracker_init (GstCVTracker * filter)
233239
#else
234240
filter->tracker = cv::TrackerMedianFlow::create();
235241
#endif
242+
filter->draw = TRUE;
236243
filter->post_debug_info = TRUE;
237244

238245
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
@@ -262,6 +269,9 @@ gst_cvtracker_set_property (GObject * object, guint prop_id,
262269
case PROP_ALGORITHM:
263270
filter->algorithm = g_value_get_enum (value);
264271
break;
272+
case PROP_DRAW:
273+
filter->draw = g_value_get_boolean (value);
274+
break;
265275
default:
266276
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
267277
break;
@@ -338,6 +348,9 @@ gst_cvtracker_get_property (GObject * object, guint prop_id,
338348
case PROP_ALGORITHM:
339349
g_value_set_enum (value, filter->algorithm);
340350
break;
351+
case PROP_DRAW:
352+
g_value_set_boolean (value, filter->draw);
353+
break;
341354
default:
342355
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
343356
break;
@@ -382,6 +395,8 @@ gst_cvtracker_transform_ip (GstOpencvVideoFilter * base,
382395
filter->roi->x, filter->roi->y, filter->roi->width,
383396
filter->roi->height);
384397
gst_element_post_message (GST_ELEMENT (filter), msg);
398+
if (filter->draw)
399+
cv::rectangle (img, *filter->roi, cv::Scalar (255, 0, 0), 2, 1);
385400
if (!(filter->post_debug_info))
386401
filter->post_debug_info = TRUE;
387402
} else if (filter->post_debug_info) {

ext/opencv/gstcvtracker.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct _GstCVTracker
8080
guint width;
8181
guint height;
8282
gint algorithm;
83+
gboolean draw;
8384
gboolean post_debug_info;
8485

8586
cv::Ptr<cv::Tracker> tracker;

0 commit comments

Comments
 (0)