Skip to content

Commit

Permalink
Merge branch 'dev-0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
c-trejos committed Feb 28, 2020
2 parents 7b9a138 + eef5b20 commit f42ea4f
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 268 deletions.
8 changes: 3 additions & 5 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.7.1.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
AC_INIT([GStreamer Inference],[0.8.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])

AG_GST_INIT

Expand Down Expand Up @@ -288,7 +288,7 @@ if test "$USE_OPENCV" = "yes"; then
fi

dnl *** r2inference ***
R2INFERENCE_REQ=0.4.1
R2INFERENCE_REQ=0.5.0
AG_GST_CHECK_FEATURE(R2INFERENCE, [RidgeRun\'s Inference Framework], r2inference, [
AG_GST_PKG_CHECK_MODULES(R2INFERENCE, r2inference-0.0 >= $R2INFERENCE_REQ)
],[],[],[
Expand Down Expand Up @@ -382,9 +382,7 @@ ext/Makefile
ext/opencv/Makefile
ext/r2inference/Makefile
gst/Makefile
gst/inferencecrop/Makefile
gst/inferencefilter/Makefile
gst/inferencedebug/Makefile
gst/inferenceutils/Makefile
gst-libs/Makefile
gst-libs/gst/Makefile
gst-libs/gst/opencv/Makefile
Expand Down
4 changes: 2 additions & 2 deletions ext/opencv/gstclassificationoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static GstFlowReturn
gst_classification_overlay_process_meta (GstInferenceBaseOverlay *
inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta,
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style);
LineStyleBoundingBox style, gdouble alpha_overlay);

enum
{
Expand Down Expand Up @@ -95,7 +95,7 @@ static GstFlowReturn
gst_classification_overlay_process_meta (GstInferenceBaseOverlay *
inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta,
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style)
LineStyleBoundingBox style, gdouble alpha_overlay)
{
GstClassificationMeta *class_meta;
gint index, i;
Expand Down
4 changes: 2 additions & 2 deletions ext/opencv/gstdetectionoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_detection_overlay_debug_category);
static GstFlowReturn gst_detection_overlay_process_meta (GstInferenceBaseOverlay
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
GstMeta * meta, gdouble font_scale, gint thickness, gchar ** labels_list,
gint num_labels, LineStyleBoundingBox style);
gint num_labels, LineStyleBoundingBox style, gdouble alpha_overlay);

enum
{
Expand Down Expand Up @@ -104,7 +104,7 @@ static GstFlowReturn
gst_detection_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style)
LineStyleBoundingBox style, gdouble alpha_overlay)
{
GstDetectionMeta *detect_meta;
gint i;
Expand Down
4 changes: 2 additions & 2 deletions ext/opencv/gstembeddingoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void gst_embedding_overlay_finalize (GObject * object);
static GstFlowReturn gst_embedding_overlay_process_meta (GstInferenceBaseOverlay
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
GstMeta * meta, gdouble font_scale, gint thickness, gchar ** labels_list,
gint num_labels, LineStyleBoundingBox style);
gint num_labels, LineStyleBoundingBox style, gdouble alpha_overlay);
static gboolean gst_embedding_overlay_set_embeddings (GstEmbeddingOverlay *
embedding_overlay, const GValue * value);

Expand Down Expand Up @@ -209,7 +209,7 @@ static GstFlowReturn
gst_embedding_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style)
LineStyleBoundingBox, gdouble alpha_overlay )
{
GstEmbeddingOverlay *embedding_overlay =
GST_EMBEDDING_OVERLAY (inference_overlay);
Expand Down
40 changes: 24 additions & 16 deletions ext/opencv/gstinferenceoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static const cv::Scalar colors[] = {
#define CHOSEN_COLOR 14
#define OVERLAY_HEIGHT 50
#define OVERLAY_WIDTH 30
#define OVERLAY_X_POSITION 0
#define LINES_GAP 20

GST_DEBUG_CATEGORY_STATIC (gst_inference_overlay_debug_category);
Expand All @@ -67,7 +68,7 @@ static void gst_inference_overlay_get_property (GObject * object,
static GstFlowReturn gst_inference_overlay_process_meta (GstInferenceBaseOverlay
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
GstMeta * meta, gdouble font_scale, gint thickness, gchar ** labels_list,
gint num_labels, LineStyleBoundingBox style);
gint num_labels, LineStyleBoundingBox style, gdouble alpha_overlay);
static void draw_line (cv::Mat & img, cv::Point pt1, cv::Point pt2,
cv::Scalar color, gint thickness, LineStyleBoundingBox style, gint gap);

Expand Down Expand Up @@ -193,7 +194,7 @@ draw_line (cv::Mat & img, cv::Point pt1, cv::Point pt2, cv::Scalar color,
static void
gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style)
LineStyleBoundingBox style, gdouble alpha_overlay)
{
cv::Size size;
cv::String label;
Expand All @@ -203,9 +204,10 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
cv::String prob;
BoundingBox box;
gint classes = 0;
gdouble alpha = 0.5;
cv::Mat alpha_overlay;
gdouble alpha = alpha_overlay;
gint width, height, x, y = 0;
cv::Size max_size = cv::Size(0,0);
cv::Size current_size = cv::Size(0,0);

g_return_if_fail (pred != NULL);

Expand All @@ -217,7 +219,7 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
(GstInferencePrediction *) tree_iter->data;

gst_get_meta (predict, cv_mat, font_scale, thickness,
labels_list, num_labels, style);
labels_list, num_labels, style, alpha_overlay);
}

if (!pred->enabled) {
Expand All @@ -227,6 +229,10 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,

box = pred->bbox;

if (TRUE == G_NODE_IS_ROOT (pred->predictions)) {
box.width = 0;
}

for (iter = pred->classifications; iter != NULL; iter = g_list_next (iter)) {
GstInferenceClassification *classification = (GstInferenceClassification *)
iter->data;
Expand All @@ -242,26 +248,28 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
label = cv::format ("Label #%d : %0.3f", classification->class_id,
classification->class_prob);
}
cv::putText (cv_mat, label, cv::Point (box.x + box.width,
cv::putText (cv_mat, label, cv::Point (box.x + OVERLAY_X_POSITION,
box.y + classes * OVERLAY_WIDTH), cv::FONT_HERSHEY_PLAIN,
font_scale, cv::Scalar::all (0), thickness);
}

cv::Size text = cv::getTextSize (label, cv::FONT_HERSHEY_PLAIN, font_scale,
current_size = cv::getTextSize (label, cv::FONT_HERSHEY_PLAIN, font_scale,
thickness, 0);
if(current_size.width > max_size.width){
max_size = current_size;
}
}

if ((box.x + box.width) < 0) {
if ((box.x + OVERLAY_X_POSITION) < 0) {
x = 0;
} else if ((int) (box.x + box.width) >= cv_mat.cols) {
} else if ((int) (box.x + OVERLAY_X_POSITION) >= cv_mat.cols) {
x = cv_mat.cols - 1;
} else {
x = box.x + box.width;
x = box.x + OVERLAY_X_POSITION;
}

if ((int) (x + box.width + text.width) >= cv_mat.cols) {
if ((int) (x + OVERLAY_X_POSITION + max_size.width) >= cv_mat.cols) {
width = cv_mat.cols - x - 1;
} else {
width = text.width;
width = max_size.width;
}

if ((int) (box.y + OVERLAY_HEIGHT * classes) >= cv_mat.rows) {
Expand Down Expand Up @@ -315,7 +323,7 @@ static GstFlowReturn
gst_inference_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
gint thickness, gchar ** labels_list, gint num_labels,
LineStyleBoundingBox style)
LineStyleBoundingBox style, gdouble alpha_overlay)
{
GstInferenceMeta *detect_meta;

Expand All @@ -326,7 +334,7 @@ gst_inference_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
detect_meta = (GstInferenceMeta *) meta;

gst_get_meta (detect_meta->prediction, cv_mat, font_scale, thickness,
labels_list, num_labels, style);
labels_list, num_labels, style, alpha_overlay);

return GST_FLOW_OK;
}
7 changes: 5 additions & 2 deletions ext/r2inference/gsttinyyolov2.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov2_debug_category);
#define MIN_IOU_THRESH 0
#define DEFAULT_IOU_THRESH 0.30

#define TOTAL_CLASSES 20
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 @@ -328,7 +329,8 @@ 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);

gst_inference_print_boxes (vi, gst_tinyyolov2_debug_category, detect_meta);

Expand Down Expand Up @@ -361,7 +363,8 @@ 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 Down
12 changes: 8 additions & 4 deletions ext/r2inference/gsttinyyolov3.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov3_debug_category);
#define MIN_IOU_THRESH 0
#define DEFAULT_IOU_THRESH 0.40

#define TOTAL_CLASSES 80

/* prototypes */
static void gst_tinyyolov3_set_property (GObject * object,
guint property_id, const GValue * value, GParamSpec * pspec);
Expand Down Expand Up @@ -292,9 +294,10 @@ gst_tinyyolov3_postprocess_old (GstVideoInference * vi,
detect_meta->num_boxes = 0;
tinyyolov3 = GST_TINYYOLOV3 (vi);

gst_create_boxes (vi, prediction, valid_prediction,
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);

gst_inference_print_boxes (vi, gst_tinyyolov3_debug_category, detect_meta);

Expand Down Expand Up @@ -325,9 +328,10 @@ gst_tinyyolov3_postprocess_new (GstVideoInference * vi,
GST_LOG_OBJECT (tinyyolov3, "Postprocess Meta");

/* Create boxes from prediction data */
gst_create_boxes (vi, prediction, valid_prediction,
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 Down
22 changes: 20 additions & 2 deletions gst-libs/gst/opencv/gstinferencebaseoverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ GST_DEBUG_CATEGORY_STATIC (gst_inference_base_overlay_debug_category);
#define DEFAULT_STYLE CLASSIC
#define MAX_STYLE DASHED

#define DEFAULT_ALPHA_OVERLAY 1.0
#define MIN_ALPHA_OVERLAY 0
#define MAX_ALPHA_OVERLAY 1.0

enum
{
PROP_0,
PROP_FONT_SCALE,
PROP_THICKNESS,
PROP_LABELS,
PROP_STYLE
PROP_STYLE,
PROP_ALPHA_OVERLAY
};

GType
Expand Down Expand Up @@ -79,6 +84,7 @@ struct _GstInferenceBaseOverlayPrivate
gchar **labels_list;
gint num_labels;
LineStyleBoundingBox style;
gdouble alpha_overlay;
};
/* prototypes */
static void gst_inference_base_overlay_set_property (GObject * object,
Expand Down Expand Up @@ -142,6 +148,9 @@ gst_inference_base_overlay_class_init (GstInferenceBaseOverlayClass * klass)
g_param_spec_enum ("style", "style",
"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));

base_transform_class->start =
GST_DEBUG_FUNCPTR (gst_inference_base_overlay_start);
Expand All @@ -163,6 +172,7 @@ gst_inference_base_overlay_init (GstInferenceBaseOverlay * inference_overlay)
priv->labels_list = DEFAULT_LABELS;
priv->num_labels = DEFAULT_NUM_LABELS;
priv->style = DEFAULT_STYLE;
priv->alpha_overlay = DEFAULT_ALPHA_OVERLAY;
}

void
Expand Down Expand Up @@ -205,6 +215,11 @@ gst_inference_base_overlay_set_property (GObject * object, guint property_id,
GST_DEBUG_OBJECT (inference_overlay, "Changed box style to %d",
priv->style);
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);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down Expand Up @@ -235,6 +250,9 @@ gst_inference_base_overlay_get_property (GObject * object, guint property_id,
case PROP_STYLE:
g_value_set_enum (value, priv->style);
break;
case PROP_ALPHA_OVERLAY:
g_value_set_double (value, priv->alpha_overlay);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down Expand Up @@ -351,7 +369,7 @@ gst_inference_base_overlay_transform_frame_ip (GstVideoFilter * trans,
ret =
io_class->process_meta (inference_overlay, cv_mat, frame, meta,
priv->font_scale, priv->thickness, priv->labels_list, priv->num_labels,
priv->style);
priv->style, priv->alpha_overlay);

out:
return ret;
Expand Down
3 changes: 2 additions & 1 deletion gst-libs/gst/opencv/gstinferencebaseoverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct _GstInferenceBaseOverlayClass

GstFlowReturn (* process_meta) (GstInferenceBaseOverlay * inference_base_overlay,
cv::Mat &mat, GstVideoFrame * frame, GstMeta* meta, gdouble font_scale,
gint thickness, gchar **labels_list, gint num_labels, LineStyleBoundingBox style);
gint thickness, gchar **labels_list, gint num_labels, LineStyleBoundingBox style,
gdouble alpha_overlay);

GType meta_type;
};
Expand Down
Loading

0 comments on commit f42ea4f

Please sign in to comment.