Skip to content

Commit a633cdc

Browse files
committed
Merge branch 'dev-0.3'
2 parents 098bc00 + 5448f7b commit a633cdc

18 files changed

+792
-526
lines changed

common

Submodule common updated from cd1dee0 to 742c09d

configure.ac

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dnl please read gstreamer/docs/random/autotools before changing this file
55
dnl initialize autoconf
66
dnl releases only do -Wall, git and prerelease does -Werror too
77
dnl use a three digit version number for releases, and four for git/pre
8-
AC_INIT([GStreamer Inference],[0.2.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
8+
AC_INIT([GStreamer Inference],[0.3.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
99

1010
AG_GST_INIT
1111

@@ -373,17 +373,18 @@ Makefile
373373
common/Makefile
374374
common/m4/Makefile
375375
docs/Makefile
376-
docs/version.entities
377376
docs/plugins/Makefile
377+
docs/version.entities
378+
ext/Makefile
379+
ext/opencv/Makefile
380+
ext/r2inference/Makefile
378381
gst-libs/Makefile
379382
gst-libs/gst/Makefile
383+
gst-libs/gst/opencv/Makefile
380384
gst-libs/gst/r2inference/Makefile
381385
m4/Makefile
382-
ext/Makefile
383-
ext/r2inference/Makefile
384-
ext/opencv/Makefile
385-
tests/Makefile
386386
tests/check/Makefile
387+
tests/Makefile
387388
tests/examples/classification/Makefile
388389
tests/examples/detection/Makefile
389390
tests/examples/Makefile

ext/opencv/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ libgstinferenceoverlay_la_LIBADD = \
3131
$(GST_VIDEO_LIBS) \
3232
$(OPENCV_LIBS) \
3333
$(R2INFERENCE_LIBS) \
34-
$(top_builddir)/gst-libs/gst/r2inference/libgstinference-@[email protected]
34+
$(top_builddir)/gst-libs/gst/r2inference/libgstinference-@[email protected] \
35+
$(top_builddir)/gst-libs/gst/opencv/libgstinferenceoverlay-@[email protected]
3536

3637
libgstinferenceoverlay_la_LDFLAGS = \
3738
$(GST_PLUGIN_LDFLAGS)

ext/opencv/gstclassificationoverlay.cc

+34-226
Original file line numberDiff line numberDiff line change
@@ -31,71 +31,44 @@
3131
#include "opencv2/highgui.hpp"
3232
#endif
3333

34+
static const cv::Scalar black = cv::Scalar (0, 0, 0);
35+
static const cv::Scalar white = cv::Scalar (255, 255, 255);
36+
3437
GST_DEBUG_CATEGORY_STATIC (gst_classification_overlay_debug_category);
3538
#define GST_CAT_DEFAULT gst_classification_overlay_debug_category
3639

37-
#define MIN_FONT_SCALE 0
38-
#define DEFAULT_FONT_SCALE 1.5
39-
#define MAX_FONT_SCALE 100
40-
#define MIN_BOX_THICKNESS 1
41-
#define DEFAULT_BOX_THICKNESS 2
42-
#define MAX_BOX_THICKNESS 100
43-
#define DEFAULT_LABELS NULL
44-
#define DEFAULT_NUM_LABELS 0
45-
4640
/* prototypes */
47-
static void gst_classification_overlay_set_property (GObject * object,
48-
guint property_id, const GValue * value, GParamSpec * pspec);
49-
static void gst_classification_overlay_get_property (GObject * object,
50-
guint property_id, GValue * value, GParamSpec * pspec);
51-
static void gst_classification_overlay_dispose (GObject * object);
52-
static void gst_classification_overlay_finalize (GObject * object);
53-
54-
static gboolean gst_classification_overlay_start (GstBaseTransform * trans);
55-
static gboolean gst_classification_overlay_stop (GstBaseTransform * trans);
56-
static GstFlowReturn
57-
gst_classification_overlay_transform_frame_ip (GstVideoFilter * trans,
58-
GstVideoFrame * frame);
41+
static GstFlowReturn gst_classification_overlay_process_meta (GstVideoFrame *
42+
frame, GstMeta * meta, gdouble font_scale, gint thickness,
43+
gchar ** labels_list, gint num_labels);
5944

6045
enum
6146
{
62-
PROP_0,
63-
PROP_FONT_SCALE,
64-
PROP_BOX_THICKNESS,
65-
PROP_LABELS
47+
PROP_0
6648
};
6749

68-
/* pad templates */
69-
70-
#define VIDEO_SRC_CAPS \
71-
GST_VIDEO_CAPS_MAKE("{ RGB }")
72-
73-
#define VIDEO_SINK_CAPS \
74-
GST_VIDEO_CAPS_MAKE("{ RGB }")
50+
struct _GstClassificationOverlay
51+
{
52+
GstInferenceOverlay parent;
53+
};
7554

55+
struct _GstClassificationOverlayClass
56+
{
57+
GstInferenceOverlay parent;
58+
};
7659

7760
/* class initialization */
7861

7962
G_DEFINE_TYPE_WITH_CODE (GstClassificationOverlay, gst_classification_overlay,
80-
GST_TYPE_VIDEO_FILTER,
63+
GST_TYPE_INFERENCE_OVERLAY,
8164
GST_DEBUG_CATEGORY_INIT (gst_classification_overlay_debug_category,
82-
"classification_overlay", 0,
65+
"classificationoverlay", 0,
8366
"debug category for classification_overlay element"));
8467

8568
static void
8669
gst_classification_overlay_class_init (GstClassificationOverlayClass * klass)
8770
{
88-
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
89-
GstBaseTransformClass *base_transform_class =
90-
GST_BASE_TRANSFORM_CLASS (klass);
91-
GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
92-
93-
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
94-
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
95-
gst_caps_from_string (VIDEO_SRC_CAPS)));
96-
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
97-
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
98-
gst_caps_from_string (VIDEO_SINK_CAPS)));
71+
GstInferenceOverlayClass *io_class = GST_INFERENCE_OVERLAY_CLASS (klass);
9972

10073
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
10174
"classificationoverlay", "Filter",
@@ -107,194 +80,34 @@ gst_classification_overlay_class_init (GstClassificationOverlayClass * klass)
10780
" Miguel Taylor <[email protected]> \n\t\t\t"
10881
" Greivin Fallas <[email protected]>");
10982

110-
gobject_class->set_property = gst_classification_overlay_set_property;
111-
gobject_class->get_property = gst_classification_overlay_get_property;
112-
gobject_class->dispose = gst_classification_overlay_dispose;
113-
gobject_class->finalize = gst_classification_overlay_finalize;
114-
115-
g_object_class_install_property (gobject_class, PROP_FONT_SCALE,
116-
g_param_spec_double ("font-scale", "font", "Font scale", MIN_FONT_SCALE,
117-
MAX_FONT_SCALE, DEFAULT_FONT_SCALE, G_PARAM_READWRITE));
118-
119-
g_object_class_install_property (gobject_class, PROP_BOX_THICKNESS,
120-
g_param_spec_int ("thickness", "thickness",
121-
"Box line thickness in pixels", MIN_BOX_THICKNESS, MAX_BOX_THICKNESS,
122-
DEFAULT_BOX_THICKNESS, G_PARAM_READWRITE));
123-
124-
g_object_class_install_property (gobject_class, PROP_LABELS,
125-
g_param_spec_string ("labels", "labels",
126-
"Semicolon separated string containing inference labels",
127-
DEFAULT_LABELS, G_PARAM_READWRITE));
128-
129-
base_transform_class->start =
130-
GST_DEBUG_FUNCPTR (gst_classification_overlay_start);
131-
base_transform_class->stop =
132-
GST_DEBUG_FUNCPTR (gst_classification_overlay_stop);
133-
video_filter_class->transform_frame_ip =
134-
GST_DEBUG_FUNCPTR (gst_classification_overlay_transform_frame_ip);
135-
83+
io_class->process_meta =
84+
GST_DEBUG_FUNCPTR (gst_classification_overlay_process_meta);
85+
io_class->meta_type = GST_CLASSIFICATION_META_API_TYPE;
13686
}
13787

13888
static void
13989
gst_classification_overlay_init (GstClassificationOverlay *
14090
classification_overlay)
14191
{
142-
classification_overlay->font_scale = DEFAULT_FONT_SCALE;
143-
classification_overlay->box_thickness = DEFAULT_BOX_THICKNESS;
144-
classification_overlay->labels = DEFAULT_LABELS;
145-
classification_overlay->labels_list = DEFAULT_LABELS;
146-
classification_overlay->num_labels = DEFAULT_NUM_LABELS;
147-
}
148-
149-
void
150-
gst_classification_overlay_set_property (GObject * object, guint property_id,
151-
const GValue * value, GParamSpec * pspec)
152-
{
153-
GstClassificationOverlay *classification_overlay =
154-
GST_CLASSIFICATION_OVERLAY (object);
155-
156-
GST_DEBUG_OBJECT (classification_overlay, "set_property");
157-
158-
switch (property_id) {
159-
case PROP_FONT_SCALE:
160-
classification_overlay->font_scale = g_value_get_double (value);
161-
GST_DEBUG_OBJECT (classification_overlay, "Changed font scale to %lf",
162-
classification_overlay->font_scale);
163-
break;
164-
case PROP_BOX_THICKNESS:
165-
classification_overlay->box_thickness = g_value_get_int (value);
166-
GST_DEBUG_OBJECT (classification_overlay, "Changed box thickness to %d",
167-
classification_overlay->box_thickness);
168-
break;
169-
case PROP_LABELS:
170-
if (classification_overlay->labels != NULL) {
171-
g_free (classification_overlay->labels);
172-
}
173-
if (classification_overlay->labels_list != NULL) {
174-
g_strfreev (classification_overlay->labels_list);
175-
}
176-
classification_overlay->labels = g_value_dup_string (value);
177-
classification_overlay->labels_list =
178-
g_strsplit (g_value_get_string (value), ";", 0);
179-
classification_overlay->num_labels =
180-
g_strv_length (classification_overlay->labels_list);
181-
GST_DEBUG_OBJECT (classification_overlay, "Changed inference labels %s",
182-
classification_overlay->labels);
183-
break;
184-
default:
185-
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
186-
break;
187-
}
188-
}
189-
190-
void
191-
gst_classification_overlay_get_property (GObject * object, guint property_id,
192-
GValue * value, GParamSpec * pspec)
193-
{
194-
GstClassificationOverlay *classification_overlay =
195-
GST_CLASSIFICATION_OVERLAY (object);
196-
197-
GST_DEBUG_OBJECT (classification_overlay, "get_property");
198-
199-
switch (property_id) {
200-
case PROP_FONT_SCALE:
201-
g_value_set_double (value, classification_overlay->font_scale);
202-
break;
203-
case PROP_BOX_THICKNESS:
204-
g_value_set_int (value, classification_overlay->box_thickness);
205-
break;
206-
case PROP_LABELS:
207-
g_value_set_string (value, classification_overlay->labels);
208-
break;
209-
default:
210-
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
211-
break;
212-
}
21392
}
21493

215-
void
216-
gst_classification_overlay_dispose (GObject * object)
217-
{
218-
GstClassificationOverlay *classification_overlay =
219-
GST_CLASSIFICATION_OVERLAY (object);
220-
221-
GST_DEBUG_OBJECT (classification_overlay, "dispose");
222-
223-
/* clean up as possible. may be called multiple times */
224-
if (classification_overlay->labels_list != NULL) {
225-
g_strfreev (classification_overlay->labels_list);
226-
}
227-
if (classification_overlay->labels != NULL) {
228-
g_free (classification_overlay->labels);
229-
}
230-
231-
G_OBJECT_CLASS (gst_classification_overlay_parent_class)->dispose (object);
232-
}
233-
234-
void
235-
gst_classification_overlay_finalize (GObject * object)
236-
{
237-
GstClassificationOverlay *classification_overlay =
238-
GST_CLASSIFICATION_OVERLAY (object);
239-
240-
GST_DEBUG_OBJECT (classification_overlay, "finalize");
241-
242-
/* clean up object here */
243-
244-
G_OBJECT_CLASS (gst_classification_overlay_parent_class)->finalize (object);
245-
}
246-
247-
static gboolean
248-
gst_classification_overlay_start (GstBaseTransform * trans)
249-
{
250-
GstClassificationOverlay *classification_overlay =
251-
GST_CLASSIFICATION_OVERLAY (trans);
252-
253-
GST_DEBUG_OBJECT (classification_overlay, "start");
254-
255-
return TRUE;
256-
}
257-
258-
static gboolean
259-
gst_classification_overlay_stop (GstBaseTransform * trans)
260-
{
261-
GstClassificationOverlay *classification_overlay =
262-
GST_CLASSIFICATION_OVERLAY (trans);
263-
264-
GST_DEBUG_OBJECT (classification_overlay, "stop");
265-
266-
return TRUE;
267-
}
268-
269-
/* transform */
27094
static GstFlowReturn
271-
gst_classification_overlay_transform_frame_ip (GstVideoFilter * trans,
272-
GstVideoFrame * frame)
95+
gst_classification_overlay_process_meta (GstVideoFrame * frame, GstMeta * meta,
96+
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels)
27397
{
274-
GstClassificationOverlay *classification_overlay =
275-
GST_CLASSIFICATION_OVERLAY (trans);
27698
GstClassificationMeta *class_meta;
27799
gint index, i, width, height;
278100
gdouble max, current;
279101
cv::Mat cv_mat;
280102
cv::String str;
281103
cv::Size size;
282-
const gint bpp = 3;
283-
cv::Scalar black = cv::Scalar (0, 0, 0);
284-
cv::Scalar white = cv::Scalar (255, 255, 255);
285104

286-
width = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0) / bpp;
105+
width =
106+
GST_VIDEO_FRAME_COMP_STRIDE (frame,
107+
0) / GST_VIDEO_FRAME_N_COMPONENTS (frame);
287108
height = GST_VIDEO_FRAME_HEIGHT (frame);
288109

289-
class_meta =
290-
(GstClassificationMeta *) gst_buffer_get_meta (frame->buffer,
291-
GST_CLASSIFICATION_META_API_TYPE);
292-
if (NULL == class_meta) {
293-
GST_LOG_OBJECT (trans, "No classification meta found");
294-
return GST_FLOW_OK;
295-
}
296-
297-
GST_LOG_OBJECT (trans, "Valid classification meta found");
110+
class_meta = (GstClassificationMeta *) meta;
298111

299112
/* Get the most probable label */
300113
index = 0;
@@ -306,27 +119,22 @@ gst_classification_overlay_transform_frame_ip (GstVideoFilter * trans,
306119
index = i;
307120
}
308121
}
309-
if (classification_overlay->num_labels > index) {
310-
str = cv::format ("%s prob:%f", classification_overlay->labels_list[index],
311-
max);
122+
if (num_labels > index) {
123+
str = cv::format ("%s prob:%f", labels_list[index], max);
312124
} else {
313125
str = cv::format ("Label #%d prob:%f", index, max);
314126
}
315127
/* Get size of string on screen */
316128
int baseline = 0;
317129
size =
318-
cv::getTextSize (str, cv::FONT_HERSHEY_TRIPLEX,
319-
classification_overlay->box_thickness, classification_overlay->font_scale,
130+
cv::getTextSize (str, cv::FONT_HERSHEY_TRIPLEX, thickness, font_scale,
320131
&baseline);
321132
/* Put string on screen */
322133
cv_mat = cv::Mat (height, width, CV_8UC3, (char *) frame->data[0]);
323-
cv::putText (cv_mat, str, cv::Point (0, size.height),
324-
cv::FONT_HERSHEY_PLAIN, classification_overlay->font_scale, white,
325-
classification_overlay->box_thickness + 1);
326-
327-
cv::putText (cv_mat, str, cv::Point (0, size.height),
328-
cv::FONT_HERSHEY_PLAIN, classification_overlay->font_scale, black,
329-
classification_overlay->box_thickness);
134+
cv::putText (cv_mat, str, cv::Point (0, size.height), cv::FONT_HERSHEY_PLAIN,
135+
font_scale, white, thickness + 1);
136+
cv::putText (cv_mat, str, cv::Point (0, size.height), cv::FONT_HERSHEY_PLAIN,
137+
font_scale, black, thickness);
330138

331139
return GST_FLOW_OK;
332140
}

0 commit comments

Comments
 (0)