Skip to content

Commit

Permalink
Merge branch 'dev-0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgruner committed Mar 13, 2020
2 parents f42ea4f + e248ab8 commit 95de4f6
Show file tree
Hide file tree
Showing 17 changed files with 818 additions and 110 deletions.
52 changes: 40 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dnl please read gstreamer/docs/random/autotools before changing this file
dnl initialize autoconf
dnl releases only do -Wall, git and prerelease does -Werror too
dnl use a three digit version number for releases, and four for git/pre
AC_INIT([GStreamer Inference],[0.8.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
AC_INIT([GStreamer Inference],[0.9.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])

AG_GST_INIT

Expand Down Expand Up @@ -268,27 +268,55 @@ echo
dnl *** opencv ***
OPENCV_REQ=2.3.1
translit(dnm, m, l) AM_CONDITIONAL(USE_OPENCV, true)
AG_GST_CHECK_FEATURE(OPENCV, [OpenCV computer vision library], opencv, [
AG_GST_PKG_CHECK_MODULES(OPENCV, opencv >= $OPENCV_REQ )
])
dnl define conditional for opencv versions 2.3.1 to 3.1.0
AG_GST_CHECK_FEATURE(OPENCV, [OpenCV computer vision library], opencv,
[
PKG_CHECK_MODULES(OPENCV, opencv4,
[
HAVE_OPENCV="yes"
HAVE_OPENCV4="yes"
],
[
HAVE_OPENCV="no"
HAVE_OPENCV4="no"
AC_MSG_NOTICE($OPENCV_PKG_ERRORS)
PKG_CHECK_MODULES(OPENCV, opencv >= OPENCV_REQ ,
[
HAVE_OPENCV="yes"
HAVE_OPENCV4="no"
],
[
HAVE_OPENCV="no"
AC_MSG_NOTICE($OPENCV_PKG_ERRORS)
])
])
])

dnl define conditional for opencv versions 2.3.1 to 4.0.0
if test "$USE_OPENCV" = "yes"; then
OCV_BASE_VERSION_MAJOR=3
OCV_BASE_VERSION_MINOR=2
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv | awk -F. '{print $1}')
OCV_VERSION_MINOR=$(pkg-config --modversion opencv | awk -F. '{print $2}')
if test "$OCV_VERSION_MAJOR" -lt "$OCV_BASE_VERSION_MAJOR"; then
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
if test "$HAVE_OPENCV4" = "yes"; then
AC_DEFINE([OCV_VERSION_4_0], [1], [Defined if OpenCV version is 4])
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv4 | awk -F. '{print $1}')
OCV_VERSION_MINOR=$(pkg-config --modversion opencv4 | awk -F. '{print $2}')
else
if test "$OCV_VERSION_MINOR" -lt "$OCV_BASE_VERSION_MINOR"; then
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
if test "$HAVE_OPENCV4" = "no"; then
OCV_VERSION_MAJOR=$(pkg-config --modversion opencv | awk -F. '{print $1}')
OCV_VERSION_MINOR=$(pkg-config --modversion opencv | awk -F. '{print $2}')
if test "$OCV_VERSION_MAJOR" -lt "$OCV_BASE_VERSION_MAJOR"; then
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
else
if test "$OCV_VERSION_MINOR" -lt "$OCV_BASE_VERSION_MINOR"; then
AC_DEFINE([OCV_VERSION_LT_3_2], [1], [Defined if OpenCV version is less than 3.2])
fi
fi
fi
fi
AC_MSG_NOTICE([OpenCV version: $OCV_VERSION_MAJOR.$OCV_VERSION_MINOR])
fi

dnl *** r2inference ***
R2INFERENCE_REQ=0.5.0
R2INFERENCE_REQ=0.5.2
AG_GST_CHECK_FEATURE(R2INFERENCE, [RidgeRun\'s Inference Framework], r2inference, [
AG_GST_PKG_CHECK_MODULES(R2INFERENCE, r2inference-0.0 >= $R2INFERENCE_REQ)
],[],[],[
Expand Down
1 change: 1 addition & 0 deletions ext/opencv/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ libgstinferenceoverlayplugin_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_VIDEO_CFLAGS) \
$(R2INFERENCE_CFLAGS) \
$(OPENCV_CFLAGS) \
-I$(top_srcdir)/gst-libs


Expand Down
1 change: 0 additions & 1 deletion ext/r2inference/gstinference.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ plugin_init (GstPlugin * plugin)
goto out;
}


ret = gst_element_register (plugin, "facenetv1", GST_RANK_NONE,
GST_TYPE_FACENETV1);
if (!ret) {
Expand Down
23 changes: 16 additions & 7 deletions ext/r2inference/gsttinyyolov2.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov2_debug_category);
#define DEFAULT_IOU_THRESH 0.30

#define TOTAL_CLASSES 20
#define TOTAL_BOXES 845

const gfloat box_anchors[] =
{ 1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52 };

Expand Down Expand Up @@ -317,7 +319,8 @@ gst_tinyyolov2_postprocess_old (GstVideoInference * vi,
GstVideoInfo * info_model, gboolean * valid_prediction)
{
GstTinyyolov2 *tinyyolov2;
gdouble *probabilities = NULL;
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
gint i;

GstDetectionMeta *detect_meta = (GstDetectionMeta *) meta_model;

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

gst_create_boxes (vi, prediction, valid_prediction,
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov2->obj_thresh,
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, probabilities,
TOTAL_CLASSES);

/* Free probabilities */
for (i = 0; i < detect_meta->num_boxes; i++) {
g_free (probabilities[i]);
}
g_free (probabilities);

gst_inference_print_boxes (vi, gst_tinyyolov2_debug_category, detect_meta);

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

g_return_val_if_fail (vi != NULL, FALSE);
g_return_val_if_fail (meta_model != NULL, FALSE);
Expand All @@ -363,7 +372,7 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
/* Create boxes from prediction data */
gst_create_boxes (vi, prediction, valid_prediction,
&boxes, &num_boxes, tinyyolov2->obj_thresh,
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, probabilities,
TOTAL_CLASSES);

GST_LOG_OBJECT (tinyyolov2, "Number of predictions: %d", num_boxes);
Expand All @@ -376,14 +385,14 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
for (i = 0; i < num_boxes; i++) {
GstInferencePrediction *pred =
gst_create_prediction_from_box (vi, &boxes[i], labels_list, num_labels,
probabilities);

probabilities[i]);
gst_inference_prediction_append (imeta->prediction, pred);
g_free (probabilities[i]);
}

/* Free boxes after creation */
g_free (boxes);

g_free (probabilities);
/* Log predictions */
gst_inference_print_predictions (vi, gst_tinyyolov2_debug_category, imeta);

Expand Down
20 changes: 15 additions & 5 deletions ext/r2inference/gsttinyyolov3.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov3_debug_category);
#define DEFAULT_IOU_THRESH 0.40

#define TOTAL_CLASSES 80
#define TOTAL_BOXES 2535

/* prototypes */
static void gst_tinyyolov3_set_property (GObject * object,
Expand Down Expand Up @@ -284,7 +285,8 @@ gst_tinyyolov3_postprocess_old (GstVideoInference * vi,
GstVideoInfo * info_model, gboolean * valid_prediction)
{
GstTinyyolov3 *tinyyolov3;
gdouble *probabilities = NULL;
gdouble **probabilities = g_malloc (sizeof (gdouble) * TOTAL_BOXES);
gint i;

GstDetectionMeta *detect_meta = (GstDetectionMeta *) meta_model;

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

gst_create_boxes_float (vi, prediction, valid_prediction,
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov3->obj_thresh,
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, probabilities,
TOTAL_CLASSES);

/* Free probabilities */
for (i = 0; i < detect_meta->num_boxes; i++) {
g_free (probabilities[i]);
}
g_free (probabilities);

gst_inference_print_boxes (vi, gst_tinyyolov3_debug_category, detect_meta);

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

g_return_val_if_fail (vi != NULL, FALSE);
g_return_val_if_fail (meta_model != NULL, FALSE);
Expand All @@ -330,7 +338,7 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
/* Create boxes from prediction data */
gst_create_boxes_float (vi, prediction, valid_prediction,
&boxes, &num_boxes, tinyyolov3->obj_thresh,
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, probabilities,
TOTAL_CLASSES);

GST_LOG_OBJECT (tinyyolov3, "Number of predictions: %d", num_boxes);
Expand All @@ -344,12 +352,14 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
for (i = 0; i < num_boxes; i++) {
GstInferencePrediction *pred =
gst_create_prediction_from_box (vi, &boxes[i], labels_list, num_labels,
probabilities);
probabilities[i]);
gst_inference_prediction_append (imeta->prediction, pred);
g_free (probabilities[i]);
}

/* Free boxes after creation */
g_free (boxes);
g_free (probabilities);

/* Log predictions */
gst_inference_print_predictions (vi, gst_tinyyolov3_debug_category, imeta);
Expand Down
1 change: 0 additions & 1 deletion gst-libs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

SUBDIRS=gst

6 changes: 5 additions & 1 deletion gst-libs/gst/opencv/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ libgstinferencebaseoverlay_@GST_API_VERSION@_la_CFLAGS= \
$(GST_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
$(OPENCV_CFLAGS) \
$(R2INFERENCE_CFLAGS)

libgstinferencebaseoverlay_@GST_API_VERSION@_la_CXXFLAGS= \
$(GST_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
$(R2INFERENCE_CFLAGS)
$(OPENCV_CFLAGS) \
$(R2INFERENCE_CFLAGS) \
-std=c++11

libgstinferencebaseoverlay_@GST_API_VERSION@_la_LIBADD= \
$(GST_LIBS) \
$(GST_BASE_LIBS) \
-lgstvideo-@GST_API_VERSION@ \
$(GST_PLUGINS_BASE_LIBS) \
$(OPENCV_LIBS) \
$(R2INFERENCE_LIBS)

gstinferencebaseoverlayincludedir=@includedir@/gstreamer-@GST_API_VERSION@/gst/opencv/
Expand Down
32 changes: 27 additions & 5 deletions gst-libs/gst/opencv/gstinferencebaseoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_inference_base_overlay_debug_category);
#define MAX_THICKNESS 100
#define DEFAULT_LABELS NULL
#define DEFAULT_NUM_LABELS 0
#define DEFAULT_ENABLE TRUE

#define MIN_STYLE CLASSIC
#define DEFAULT_STYLE CLASSIC
Expand All @@ -56,7 +57,8 @@ enum
PROP_THICKNESS,
PROP_LABELS,
PROP_STYLE,
PROP_ALPHA_OVERLAY
PROP_ALPHA_OVERLAY,
PROP_ENABLE,
};

GType
Expand Down Expand Up @@ -85,6 +87,7 @@ struct _GstInferenceBaseOverlayPrivate
gint num_labels;
LineStyleBoundingBox style;
gdouble alpha_overlay;
gboolean enable;
};
/* prototypes */
static void gst_inference_base_overlay_set_property (GObject * object,
Expand Down Expand Up @@ -149,8 +152,14 @@ gst_inference_base_overlay_class_init (GstInferenceBaseOverlayClass * klass)
"Line style to draw the bounding box", LINE_STYLE_BOUNDING_BOX,
DEFAULT_STYLE, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_ALPHA_OVERLAY,
g_param_spec_double ("alpha_overlay", "alpha", "Overlay transparency", MIN_ALPHA_OVERLAY,
MAX_ALPHA_OVERLAY, DEFAULT_ALPHA_OVERLAY, G_PARAM_READWRITE));
g_param_spec_double ("alpha_overlay", "alpha", "Overlay transparency",
MIN_ALPHA_OVERLAY, MAX_ALPHA_OVERLAY, DEFAULT_ALPHA_OVERLAY,
G_PARAM_READWRITE));

g_object_class_install_property (gobject_class, PROP_ENABLE,
g_param_spec_boolean ("enable", "Enable",
"Whether or not to overlay predictions on the buffers",
DEFAULT_ENABLE, G_PARAM_READWRITE));

base_transform_class->start =
GST_DEBUG_FUNCPTR (gst_inference_base_overlay_start);
Expand All @@ -173,6 +182,7 @@ gst_inference_base_overlay_init (GstInferenceBaseOverlay * inference_overlay)
priv->num_labels = DEFAULT_NUM_LABELS;
priv->style = DEFAULT_STYLE;
priv->alpha_overlay = DEFAULT_ALPHA_OVERLAY;
priv->enable = DEFAULT_ENABLE;
}

void
Expand Down Expand Up @@ -217,8 +227,11 @@ gst_inference_base_overlay_set_property (GObject * object, guint property_id,
break;
case PROP_ALPHA_OVERLAY:
priv->alpha_overlay = g_value_get_double (value);
GST_DEBUG_OBJECT (inference_overlay, "Changed overlay transparency to %lf",
priv->alpha_overlay);
GST_DEBUG_OBJECT (inference_overlay,
"Changed overlay transparency to %lf", priv->alpha_overlay);
break;
case PROP_ENABLE:
priv->enable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
Expand Down Expand Up @@ -253,6 +266,9 @@ gst_inference_base_overlay_get_property (GObject * object, guint property_id,
case PROP_ALPHA_OVERLAY:
g_value_set_double (value, priv->alpha_overlay);
break;
case PROP_ENABLE:
g_value_set_boolean (value, priv->enable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down Expand Up @@ -337,6 +353,12 @@ gst_inference_base_overlay_transform_frame_ip (GstVideoFilter * trans,

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

if (FALSE == priv->enable) {
GST_LOG_OBJECT (trans, "Overlay disabled");
ret = GST_FLOW_OK;
goto out;
}

meta = gst_buffer_get_meta (frame->buffer, io_class->meta_type);
if (NULL == meta) {
GST_LOG_OBJECT (trans, "No inference meta found");
Expand Down
10 changes: 9 additions & 1 deletion gst-libs/gst/opencv/gstinferencebaseoverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@
#ifndef __GST_INFERENCE_BASE_OVERLAY_H__
#define __GST_INFERENCE_BASE_OVERLAY_H__

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>
#include <gst/video/video.h>
#ifdef OCV_VERSION_LT_3_2

#ifdef OCV_VERSION_4_0
#include "opencv4/opencv2/highgui.hpp"
#include "opencv4/opencv2/imgproc.hpp"
#elif OCV_VERSION_LT_3_2
#include "opencv2/highgui/highgui.hpp"
#else
#include "opencv2/imgproc.hpp"
Expand Down
4 changes: 2 additions & 2 deletions gst-libs/gst/r2inference/gstbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
GST_DEBUG_CATEGORY_STATIC (gst_backend_debug_category);
#define GST_CAT_DEFAULT gst_backend_debug_category

#define DOUBLE_PROPERTY_DEFAULT_VALUE 0.5
#define DOUBLE_PROPERTY_DEFAULT_VALUE 0.0

class InferenceProperty {
private:
Expand Down Expand Up @@ -208,7 +208,7 @@ gst_backend_param_to_spec (r2i::ParameterMeta *param) {
spec = g_param_spec_double (param->name.c_str (),
param->name.c_str (),
param->description.c_str (),
G_MINDOUBLE,
-G_MAXDOUBLE,
G_MAXDOUBLE, DOUBLE_PROPERTY_DEFAULT_VALUE,
(GParamFlags) gst_backend_param_flags (param->flags));
break;
Expand Down
Loading

0 comments on commit 95de4f6

Please sign in to comment.