Skip to content

Commit 95de4f6

Browse files
committed
Merge branch 'dev-0.9'
2 parents f42ea4f + e248ab8 commit 95de4f6

17 files changed

+818
-110
lines changed

configure.ac

+40-12
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.8.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
8+
AC_INIT([GStreamer Inference],[0.9.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
99

1010
AG_GST_INIT
1111

@@ -268,27 +268,55 @@ echo
268268
dnl *** opencv ***
269269
OPENCV_REQ=2.3.1
270270
translit(dnm, m, l) AM_CONDITIONAL(USE_OPENCV, true)
271-
AG_GST_CHECK_FEATURE(OPENCV, [OpenCV computer vision library], opencv, [
272-
AG_GST_PKG_CHECK_MODULES(OPENCV, opencv >= $OPENCV_REQ )
273-
])
274-
dnl define conditional for opencv versions 2.3.1 to 3.1.0
271+
AG_GST_CHECK_FEATURE(OPENCV, [OpenCV computer vision library], opencv,
272+
[
273+
PKG_CHECK_MODULES(OPENCV, opencv4,
274+
[
275+
HAVE_OPENCV="yes"
276+
HAVE_OPENCV4="yes"
277+
],
278+
[
279+
HAVE_OPENCV="no"
280+
HAVE_OPENCV4="no"
281+
AC_MSG_NOTICE($OPENCV_PKG_ERRORS)
282+
PKG_CHECK_MODULES(OPENCV, opencv >= OPENCV_REQ ,
283+
[
284+
HAVE_OPENCV="yes"
285+
HAVE_OPENCV4="no"
286+
],
287+
[
288+
HAVE_OPENCV="no"
289+
AC_MSG_NOTICE($OPENCV_PKG_ERRORS)
290+
])
291+
])
292+
])
293+
294+
dnl define conditional for opencv versions 2.3.1 to 4.0.0
275295
if test "$USE_OPENCV" = "yes"; then
276296
OCV_BASE_VERSION_MAJOR=3
277297
OCV_BASE_VERSION_MINOR=2
278-
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv | awk -F. '{print $1}')
279-
OCV_VERSION_MINOR=$(pkg-config --modversion opencv | awk -F. '{print $2}')
280-
if test "$OCV_VERSION_MAJOR" -lt "$OCV_BASE_VERSION_MAJOR"; then
281-
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
298+
if test "$HAVE_OPENCV4" = "yes"; then
299+
AC_DEFINE([OCV_VERSION_4_0], [1], [Defined if OpenCV version is 4])
300+
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv4 | awk -F. '{print $1}')
301+
OCV_VERSION_MINOR=$(pkg-config --modversion opencv4 | awk -F. '{print $2}')
282302
else
283-
if test "$OCV_VERSION_MINOR" -lt "$OCV_BASE_VERSION_MINOR"; then
284-
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
303+
if test "$HAVE_OPENCV4" = "no"; then
304+
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv | awk -F. '{print $1}')
305+
OCV_VERSION_MINOR=$(pkg-config --modversion opencv | awk -F. '{print $2}')
306+
if test "$OCV_VERSION_MAJOR" -lt "$OCV_BASE_VERSION_MAJOR"; then
307+
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
308+
else
309+
if test "$OCV_VERSION_MINOR" -lt "$OCV_BASE_VERSION_MINOR"; then
310+
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
311+
fi
312+
fi
285313
fi
286314
fi
287315
AC_MSG_NOTICE([OpenCV version: $OCV_VERSION_MAJOR.$OCV_VERSION_MINOR])
288316
fi
289317

290318
dnl *** r2inference ***
291-
R2INFERENCE_REQ=0.5.0
319+
R2INFERENCE_REQ=0.5.2
292320
AG_GST_CHECK_FEATURE(R2INFERENCE, [RidgeRun\'s Inference Framework], r2inference, [
293321
AG_GST_PKG_CHECK_MODULES(R2INFERENCE, r2inference-0.0 >= $R2INFERENCE_REQ)
294322
],[],[],[

ext/opencv/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ libgstinferenceoverlayplugin_la_CFLAGS = \
1313
$(GST_PLUGINS_BASE_CFLAGS) \
1414
$(GST_VIDEO_CFLAGS) \
1515
$(R2INFERENCE_CFLAGS) \
16+
$(OPENCV_CFLAGS) \
1617
-I$(top_srcdir)/gst-libs
1718

1819

ext/r2inference/gstinference.c

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ plugin_init (GstPlugin * plugin)
8989
goto out;
9090
}
9191

92-
9392
ret = gst_element_register (plugin, "facenetv1", GST_RANK_NONE,
9493
GST_TYPE_FACENETV1);
9594
if (!ret) {

ext/r2inference/gsttinyyolov2.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov2_debug_category);
6767
#define DEFAULT_IOU_THRESH 0.30
6868

6969
#define TOTAL_CLASSES 20
70+
#define TOTAL_BOXES 845
71+
7072
const gfloat box_anchors[] =
7173
{ 1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52 };
7274

@@ -317,7 +319,8 @@ gst_tinyyolov2_postprocess_old (GstVideoInference * vi,
317319
GstVideoInfo * info_model, gboolean * valid_prediction)
318320
{
319321
GstTinyyolov2 *tinyyolov2;
320-
gdouble *probabilities = NULL;
322+
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
323+
gint i;
321324

322325
GstDetectionMeta *detect_meta = (GstDetectionMeta *) meta_model;
323326

@@ -329,9 +332,15 @@ gst_tinyyolov2_postprocess_old (GstVideoInference * vi,
329332

330333
gst_create_boxes (vi, prediction, valid_prediction,
331334
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov2->obj_thresh,
332-
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
335+
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, probabilities,
333336
TOTAL_CLASSES);
334337

338+
/* Free probabilities */
339+
for (i = 0; i < detect_meta->num_boxes; i++) {
340+
g_free (probabilities[i]);
341+
}
342+
g_free (probabilities);
343+
335344
gst_inference_print_boxes (vi, gst_tinyyolov2_debug_category, detect_meta);
336345

337346
*valid_prediction = (detect_meta->num_boxes > 0) ? TRUE : FALSE;
@@ -349,7 +358,7 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
349358
GstInferenceMeta *imeta = NULL;
350359
BBox *boxes = NULL;
351360
gint num_boxes, i;
352-
gdouble *probabilities = NULL;
361+
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
353362

354363
g_return_val_if_fail (vi != NULL, FALSE);
355364
g_return_val_if_fail (meta_model != NULL, FALSE);
@@ -363,7 +372,7 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
363372
/* Create boxes from prediction data */
364373
gst_create_boxes (vi, prediction, valid_prediction,
365374
&boxes, &num_boxes, tinyyolov2->obj_thresh,
366-
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
375+
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, probabilities,
367376
TOTAL_CLASSES);
368377

369378
GST_LOG_OBJECT (tinyyolov2, "Number of predictions: %d", num_boxes);
@@ -376,14 +385,14 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
376385
for (i = 0; i < num_boxes; i++) {
377386
GstInferencePrediction *pred =
378387
gst_create_prediction_from_box (vi, &boxes[i], labels_list, num_labels,
379-
probabilities);
380-
388+
probabilities[i]);
381389
gst_inference_prediction_append (imeta->prediction, pred);
390+
g_free (probabilities[i]);
382391
}
383392

384393
/* Free boxes after creation */
385394
g_free (boxes);
386-
395+
g_free (probabilities);
387396
/* Log predictions */
388397
gst_inference_print_predictions (vi, gst_tinyyolov2_debug_category, imeta);
389398

ext/r2inference/gsttinyyolov3.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov3_debug_category);
6464
#define DEFAULT_IOU_THRESH 0.40
6565

6666
#define TOTAL_CLASSES 80
67+
#define TOTAL_BOXES 2535
6768

6869
/* prototypes */
6970
static void gst_tinyyolov3_set_property (GObject * object,
@@ -284,7 +285,8 @@ gst_tinyyolov3_postprocess_old (GstVideoInference * vi,
284285
GstVideoInfo * info_model, gboolean * valid_prediction)
285286
{
286287
GstTinyyolov3 *tinyyolov3;
287-
gdouble *probabilities = NULL;
288+
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
289+
gint i;
288290

289291
GstDetectionMeta *detect_meta = (GstDetectionMeta *) meta_model;
290292

@@ -296,9 +298,15 @@ gst_tinyyolov3_postprocess_old (GstVideoInference * vi,
296298

297299
gst_create_boxes_float (vi, prediction, valid_prediction,
298300
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov3->obj_thresh,
299-
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
301+
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, probabilities,
300302
TOTAL_CLASSES);
301303

304+
/* Free probabilities */
305+
for (i = 0; i < detect_meta->num_boxes; i++) {
306+
g_free (probabilities[i]);
307+
}
308+
g_free (probabilities);
309+
302310
gst_inference_print_boxes (vi, gst_tinyyolov3_debug_category, detect_meta);
303311

304312
*valid_prediction = (detect_meta->num_boxes > 0) ? TRUE : FALSE;
@@ -316,7 +324,7 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
316324
GstInferenceMeta *imeta = NULL;
317325
BBox *boxes = NULL;
318326
gint num_boxes, i;
319-
gdouble *probabilities = NULL;
327+
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
320328

321329
g_return_val_if_fail (vi != NULL, FALSE);
322330
g_return_val_if_fail (meta_model != NULL, FALSE);
@@ -330,7 +338,7 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
330338
/* Create boxes from prediction data */
331339
gst_create_boxes_float (vi, prediction, valid_prediction,
332340
&boxes, &num_boxes, tinyyolov3->obj_thresh,
333-
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
341+
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, probabilities,
334342
TOTAL_CLASSES);
335343

336344
GST_LOG_OBJECT (tinyyolov3, "Number of predictions: %d", num_boxes);
@@ -344,12 +352,14 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
344352
for (i = 0; i < num_boxes; i++) {
345353
GstInferencePrediction *pred =
346354
gst_create_prediction_from_box (vi, &boxes[i], labels_list, num_labels,
347-
probabilities);
355+
probabilities[i]);
348356
gst_inference_prediction_append (imeta->prediction, pred);
357+
g_free (probabilities[i]);
349358
}
350359

351360
/* Free boxes after creation */
352361
g_free (boxes);
362+
g_free (probabilities);
353363

354364
/* Log predictions */
355365
gst_inference_print_predictions (vi, gst_tinyyolov3_debug_category, imeta);

gst-libs/Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11

22
SUBDIRS=gst
3-

gst-libs/gst/opencv/Makefile.am

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ libgstinferencebaseoverlay_@GST_API_VERSION@_la_CFLAGS= \
88
$(GST_CFLAGS) \
99
$(GST_BASE_CFLAGS) \
1010
$(GST_PLUGINS_BASE_CFLAGS) \
11+
$(OPENCV_CFLAGS) \
1112
$(R2INFERENCE_CFLAGS)
1213

1314
libgstinferencebaseoverlay_@GST_API_VERSION@_la_CXXFLAGS= \
1415
$(GST_CFLAGS) \
1516
$(GST_BASE_CFLAGS) \
1617
$(GST_PLUGINS_BASE_CFLAGS) \
17-
$(R2INFERENCE_CFLAGS)
18+
$(OPENCV_CFLAGS) \
19+
$(R2INFERENCE_CFLAGS) \
20+
-std=c++11
1821

1922
libgstinferencebaseoverlay_@GST_API_VERSION@_la_LIBADD= \
2023
$(GST_LIBS) \
2124
$(GST_BASE_LIBS) \
2225
-lgstvideo-@GST_API_VERSION@ \
2326
$(GST_PLUGINS_BASE_LIBS) \
27+
$(OPENCV_LIBS) \
2428
$(R2INFERENCE_LIBS)
2529

2630
gstinferencebaseoverlayincludedir=@includedir@/gstreamer-@GST_API_VERSION@/gst/opencv/

gst-libs/gst/opencv/gstinferencebaseoverlay.cc

+27-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_inference_base_overlay_debug_category);
4040
#define MAX_THICKNESS 100
4141
#define DEFAULT_LABELS NULL
4242
#define DEFAULT_NUM_LABELS 0
43+
#define DEFAULT_ENABLE TRUE
4344

4445
#define MIN_STYLE CLASSIC
4546
#define DEFAULT_STYLE CLASSIC
@@ -56,7 +57,8 @@ enum
5657
PROP_THICKNESS,
5758
PROP_LABELS,
5859
PROP_STYLE,
59-
PROP_ALPHA_OVERLAY
60+
PROP_ALPHA_OVERLAY,
61+
PROP_ENABLE,
6062
};
6163

6264
GType
@@ -85,6 +87,7 @@ struct _GstInferenceBaseOverlayPrivate
8587
gint num_labels;
8688
LineStyleBoundingBox style;
8789
gdouble alpha_overlay;
90+
gboolean enable;
8891
};
8992
/* prototypes */
9093
static void gst_inference_base_overlay_set_property (GObject * object,
@@ -149,8 +152,14 @@ gst_inference_base_overlay_class_init (GstInferenceBaseOverlayClass * klass)
149152
"Line style to draw the bounding box", LINE_STYLE_BOUNDING_BOX,
150153
DEFAULT_STYLE, G_PARAM_READWRITE));
151154
g_object_class_install_property (gobject_class, PROP_ALPHA_OVERLAY,
152-
g_param_spec_double ("alpha_overlay", "alpha", "Overlay transparency", MIN_ALPHA_OVERLAY,
153-
MAX_ALPHA_OVERLAY, DEFAULT_ALPHA_OVERLAY, G_PARAM_READWRITE));
155+
g_param_spec_double ("alpha_overlay", "alpha", "Overlay transparency",
156+
MIN_ALPHA_OVERLAY, MAX_ALPHA_OVERLAY, DEFAULT_ALPHA_OVERLAY,
157+
G_PARAM_READWRITE));
158+
159+
g_object_class_install_property (gobject_class, PROP_ENABLE,
160+
g_param_spec_boolean ("enable", "Enable",
161+
"Whether or not to overlay predictions on the buffers",
162+
DEFAULT_ENABLE, G_PARAM_READWRITE));
154163

155164
base_transform_class->start =
156165
GST_DEBUG_FUNCPTR (gst_inference_base_overlay_start);
@@ -173,6 +182,7 @@ gst_inference_base_overlay_init (GstInferenceBaseOverlay * inference_overlay)
173182
priv->num_labels = DEFAULT_NUM_LABELS;
174183
priv->style = DEFAULT_STYLE;
175184
priv->alpha_overlay = DEFAULT_ALPHA_OVERLAY;
185+
priv->enable = DEFAULT_ENABLE;
176186
}
177187

178188
void
@@ -217,8 +227,11 @@ gst_inference_base_overlay_set_property (GObject * object, guint property_id,
217227
break;
218228
case PROP_ALPHA_OVERLAY:
219229
priv->alpha_overlay = g_value_get_double (value);
220-
GST_DEBUG_OBJECT (inference_overlay, "Changed overlay transparency to %lf",
221-
priv->alpha_overlay);
230+
GST_DEBUG_OBJECT (inference_overlay,
231+
"Changed overlay transparency to %lf", priv->alpha_overlay);
232+
break;
233+
case PROP_ENABLE:
234+
priv->enable = g_value_get_boolean (value);
222235
break;
223236
default:
224237
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -253,6 +266,9 @@ gst_inference_base_overlay_get_property (GObject * object, guint property_id,
253266
case PROP_ALPHA_OVERLAY:
254267
g_value_set_double (value, priv->alpha_overlay);
255268
break;
269+
case PROP_ENABLE:
270+
g_value_set_boolean (value, priv->enable);
271+
break;
256272
default:
257273
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
258274
break;
@@ -337,6 +353,12 @@ gst_inference_base_overlay_transform_frame_ip (GstVideoFilter * trans,
337353

338354
g_return_val_if_fail (io_class->process_meta != NULL, GST_FLOW_ERROR);
339355

356+
if (FALSE == priv->enable) {
357+
GST_LOG_OBJECT (trans, "Overlay disabled");
358+
ret = GST_FLOW_OK;
359+
goto out;
360+
}
361+
340362
meta = gst_buffer_get_meta (frame->buffer, io_class->meta_type);
341363
if (NULL == meta) {
342364
GST_LOG_OBJECT (trans, "No inference meta found");

gst-libs/gst/opencv/gstinferencebaseoverlay.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@
2222
#ifndef __GST_INFERENCE_BASE_OVERLAY_H__
2323
#define __GST_INFERENCE_BASE_OVERLAY_H__
2424

25+
#ifdef HAVE_CONFIG_H
26+
#include "config.h"
27+
#endif
28+
2529
#include <gst/gst.h>
2630
#include <gst/video/video.h>
27-
#ifdef OCV_VERSION_LT_3_2
31+
32+
#ifdef OCV_VERSION_4_0
33+
#include "opencv4/opencv2/highgui.hpp"
34+
#include "opencv4/opencv2/imgproc.hpp"
35+
#elif OCV_VERSION_LT_3_2
2836
#include "opencv2/highgui/highgui.hpp"
2937
#else
3038
#include "opencv2/imgproc.hpp"

gst-libs/gst/r2inference/gstbackend.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
GST_DEBUG_CATEGORY_STATIC (gst_backend_debug_category);
3232
#define GST_CAT_DEFAULT gst_backend_debug_category
3333

34-
#define DOUBLE_PROPERTY_DEFAULT_VALUE 0.5
34+
#define DOUBLE_PROPERTY_DEFAULT_VALUE 0.0
3535

3636
class InferenceProperty {
3737
private:
@@ -208,7 +208,7 @@ gst_backend_param_to_spec (r2i::ParameterMeta *param) {
208208
spec = g_param_spec_double (param->name.c_str (),
209209
param->name.c_str (),
210210
param->description.c_str (),
211-
G_MINDOUBLE,
211+
-G_MAXDOUBLE,
212212
G_MAXDOUBLE, DOUBLE_PROPERTY_DEFAULT_VALUE,
213213
(GParamFlags) gst_backend_param_flags (param->flags));
214214
break;

0 commit comments

Comments
 (0)