Skip to content

Commit f42ea4f

Browse files
committed
Merge branch 'dev-0.8'
2 parents 7b9a138 + eef5b20 commit f42ea4f

28 files changed

+303
-268
lines changed

configure.ac

+3-5
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.7.1.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
8+
AC_INIT([GStreamer Inference],[0.8.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
99

1010
AG_GST_INIT
1111

@@ -288,7 +288,7 @@ if test "$USE_OPENCV" = "yes"; then
288288
fi
289289

290290
dnl *** r2inference ***
291-
R2INFERENCE_REQ=0.4.1
291+
R2INFERENCE_REQ=0.5.0
292292
AG_GST_CHECK_FEATURE(R2INFERENCE, [RidgeRun\'s Inference Framework], r2inference, [
293293
AG_GST_PKG_CHECK_MODULES(R2INFERENCE, r2inference-0.0 >= $R2INFERENCE_REQ)
294294
],[],[],[
@@ -382,9 +382,7 @@ ext/Makefile
382382
ext/opencv/Makefile
383383
ext/r2inference/Makefile
384384
gst/Makefile
385-
gst/inferencecrop/Makefile
386-
gst/inferencefilter/Makefile
387-
gst/inferencedebug/Makefile
385+
gst/inferenceutils/Makefile
388386
gst-libs/Makefile
389387
gst-libs/gst/Makefile
390388
gst-libs/gst/opencv/Makefile

ext/opencv/gstclassificationoverlay.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static GstFlowReturn
3939
gst_classification_overlay_process_meta (GstInferenceBaseOverlay *
4040
inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta,
4141
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
42-
LineStyleBoundingBox style);
42+
LineStyleBoundingBox style, gdouble alpha_overlay);
4343

4444
enum
4545
{
@@ -95,7 +95,7 @@ static GstFlowReturn
9595
gst_classification_overlay_process_meta (GstInferenceBaseOverlay *
9696
inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta,
9797
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
98-
LineStyleBoundingBox style)
98+
LineStyleBoundingBox style, gdouble alpha_overlay)
9999
{
100100
GstClassificationMeta *class_meta;
101101
gint index, i;

ext/opencv/gstdetectionoverlay.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_detection_overlay_debug_category);
5050
static GstFlowReturn gst_detection_overlay_process_meta (GstInferenceBaseOverlay
5151
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
5252
GstMeta * meta, gdouble font_scale, gint thickness, gchar ** labels_list,
53-
gint num_labels, LineStyleBoundingBox style);
53+
gint num_labels, LineStyleBoundingBox style, gdouble alpha_overlay);
5454

5555
enum
5656
{
@@ -104,7 +104,7 @@ static GstFlowReturn
104104
gst_detection_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
105105
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
106106
gint thickness, gchar ** labels_list, gint num_labels,
107-
LineStyleBoundingBox style)
107+
LineStyleBoundingBox style, gdouble alpha_overlay)
108108
{
109109
GstDetectionMeta *detect_meta;
110110
gint i;

ext/opencv/gstembeddingoverlay.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void gst_embedding_overlay_finalize (GObject * object);
5151
static GstFlowReturn gst_embedding_overlay_process_meta (GstInferenceBaseOverlay
5252
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
5353
GstMeta * meta, gdouble font_scale, gint thickness, gchar ** labels_list,
54-
gint num_labels, LineStyleBoundingBox style);
54+
gint num_labels, LineStyleBoundingBox style, gdouble alpha_overlay);
5555
static gboolean gst_embedding_overlay_set_embeddings (GstEmbeddingOverlay *
5656
embedding_overlay, const GValue * value);
5757

@@ -209,7 +209,7 @@ static GstFlowReturn
209209
gst_embedding_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
210210
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
211211
gint thickness, gchar ** labels_list, gint num_labels,
212-
LineStyleBoundingBox style)
212+
LineStyleBoundingBox, gdouble alpha_overlay )
213213
{
214214
GstEmbeddingOverlay *embedding_overlay =
215215
GST_EMBEDDING_OVERLAY (inference_overlay);

ext/opencv/gstinferenceoverlay.cc

+24-16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const cv::Scalar colors[] = {
5454
#define CHOSEN_COLOR 14
5555
#define OVERLAY_HEIGHT 50
5656
#define OVERLAY_WIDTH 30
57+
#define OVERLAY_X_POSITION 0
5758
#define LINES_GAP 20
5859

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

@@ -193,7 +194,7 @@ draw_line (cv::Mat & img, cv::Point pt1, cv::Point pt2, cv::Scalar color,
193194
static void
194195
gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
195196
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
196-
LineStyleBoundingBox style)
197+
LineStyleBoundingBox style, gdouble alpha_overlay)
197198
{
198199
cv::Size size;
199200
cv::String label;
@@ -203,9 +204,10 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
203204
cv::String prob;
204205
BoundingBox box;
205206
gint classes = 0;
206-
gdouble alpha = 0.5;
207-
cv::Mat alpha_overlay;
207+
gdouble alpha = alpha_overlay;
208208
gint width, height, x, y = 0;
209+
cv::Size max_size = cv::Size(0,0);
210+
cv::Size current_size = cv::Size(0,0);
209211

210212
g_return_if_fail (pred != NULL);
211213

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

219221
gst_get_meta (predict, cv_mat, font_scale, thickness,
220-
labels_list, num_labels, style);
222+
labels_list, num_labels, style, alpha_overlay);
221223
}
222224

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

228230
box = pred->bbox;
229231

232+
if (TRUE == G_NODE_IS_ROOT (pred->predictions)) {
233+
box.width = 0;
234+
}
235+
230236
for (iter = pred->classifications; iter != NULL; iter = g_list_next (iter)) {
231237
GstInferenceClassification *classification = (GstInferenceClassification *)
232238
iter->data;
@@ -242,26 +248,28 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
242248
label = cv::format ("Label #%d : %0.3f", classification->class_id,
243249
classification->class_prob);
244250
}
245-
cv::putText (cv_mat, label, cv::Point (box.x + box.width,
251+
cv::putText (cv_mat, label, cv::Point (box.x + OVERLAY_X_POSITION,
246252
box.y + classes * OVERLAY_WIDTH), cv::FONT_HERSHEY_PLAIN,
247253
font_scale, cv::Scalar::all (0), thickness);
248-
}
249-
250-
cv::Size text = cv::getTextSize (label, cv::FONT_HERSHEY_PLAIN, font_scale,
254+
current_size = cv::getTextSize (label, cv::FONT_HERSHEY_PLAIN, font_scale,
251255
thickness, 0);
256+
if(current_size.width > max_size.width){
257+
max_size = current_size;
258+
}
259+
}
252260

253-
if ((box.x + box.width) < 0) {
261+
if ((box.x + OVERLAY_X_POSITION) < 0) {
254262
x = 0;
255-
} else if ((int) (box.x + box.width) >= cv_mat.cols) {
263+
} else if ((int) (box.x + OVERLAY_X_POSITION) >= cv_mat.cols) {
256264
x = cv_mat.cols - 1;
257265
} else {
258-
x = box.x + box.width;
266+
x = box.x + OVERLAY_X_POSITION;
259267
}
260268

261-
if ((int) (x + box.width + text.width) >= cv_mat.cols) {
269+
if ((int) (x + OVERLAY_X_POSITION + max_size.width) >= cv_mat.cols) {
262270
width = cv_mat.cols - x - 1;
263271
} else {
264-
width = text.width;
272+
width = max_size.width;
265273
}
266274

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

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

328336
gst_get_meta (detect_meta->prediction, cv_mat, font_scale, thickness,
329-
labels_list, num_labels, style);
337+
labels_list, num_labels, style, alpha_overlay);
330338

331339
return GST_FLOW_OK;
332340
}

ext/r2inference/gsttinyyolov2.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov2_debug_category);
6666
#define MIN_IOU_THRESH 0
6767
#define DEFAULT_IOU_THRESH 0.30
6868

69+
#define TOTAL_CLASSES 20
6970
const gfloat box_anchors[] =
7071
{ 1.08, 1.19, 3.42, 4.41, 6.63, 11.38, 9.42, 5.11, 16.62, 10.52 };
7172

@@ -328,7 +329,8 @@ gst_tinyyolov2_postprocess_old (GstVideoInference * vi,
328329

329330
gst_create_boxes (vi, prediction, valid_prediction,
330331
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov2->obj_thresh,
331-
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities);
332+
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
333+
TOTAL_CLASSES);
332334

333335
gst_inference_print_boxes (vi, gst_tinyyolov2_debug_category, detect_meta);
334336

@@ -361,7 +363,8 @@ gst_tinyyolov2_postprocess_new (GstVideoInference * vi,
361363
/* Create boxes from prediction data */
362364
gst_create_boxes (vi, prediction, valid_prediction,
363365
&boxes, &num_boxes, tinyyolov2->obj_thresh,
364-
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities);
366+
tinyyolov2->prob_thresh, tinyyolov2->iou_thresh, &probabilities,
367+
TOTAL_CLASSES);
365368

366369
GST_LOG_OBJECT (tinyyolov2, "Number of predictions: %d", num_boxes);
367370

ext/r2inference/gsttinyyolov3.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_tinyyolov3_debug_category);
6363
#define MIN_IOU_THRESH 0
6464
#define DEFAULT_IOU_THRESH 0.40
6565

66+
#define TOTAL_CLASSES 80
67+
6668
/* prototypes */
6769
static void gst_tinyyolov3_set_property (GObject * object,
6870
guint property_id, const GValue * value, GParamSpec * pspec);
@@ -292,9 +294,10 @@ gst_tinyyolov3_postprocess_old (GstVideoInference * vi,
292294
detect_meta->num_boxes = 0;
293295
tinyyolov3 = GST_TINYYOLOV3 (vi);
294296

295-
gst_create_boxes (vi, prediction, valid_prediction,
297+
gst_create_boxes_float (vi, prediction, valid_prediction,
296298
&detect_meta->boxes, &detect_meta->num_boxes, tinyyolov3->obj_thresh,
297-
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities);
299+
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
300+
TOTAL_CLASSES);
298301

299302
gst_inference_print_boxes (vi, gst_tinyyolov3_debug_category, detect_meta);
300303

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

327330
/* Create boxes from prediction data */
328-
gst_create_boxes (vi, prediction, valid_prediction,
331+
gst_create_boxes_float (vi, prediction, valid_prediction,
329332
&boxes, &num_boxes, tinyyolov3->obj_thresh,
330-
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities);
333+
tinyyolov3->prob_thresh, tinyyolov3->iou_thresh, &probabilities,
334+
TOTAL_CLASSES);
331335

332336
GST_LOG_OBJECT (tinyyolov3, "Number of predictions: %d", num_boxes);
333337

gst-libs/gst/opencv/gstinferencebaseoverlay.cc

+20-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ GST_DEBUG_CATEGORY_STATIC (gst_inference_base_overlay_debug_category);
4545
#define DEFAULT_STYLE CLASSIC
4646
#define MAX_STYLE DASHED
4747

48+
#define DEFAULT_ALPHA_OVERLAY 1.0
49+
#define MIN_ALPHA_OVERLAY 0
50+
#define MAX_ALPHA_OVERLAY 1.0
51+
4852
enum
4953
{
5054
PROP_0,
5155
PROP_FONT_SCALE,
5256
PROP_THICKNESS,
5357
PROP_LABELS,
54-
PROP_STYLE
58+
PROP_STYLE,
59+
PROP_ALPHA_OVERLAY
5560
};
5661

5762
GType
@@ -79,6 +84,7 @@ struct _GstInferenceBaseOverlayPrivate
7984
gchar **labels_list;
8085
gint num_labels;
8186
LineStyleBoundingBox style;
87+
gdouble alpha_overlay;
8288
};
8389
/* prototypes */
8490
static void gst_inference_base_overlay_set_property (GObject * object,
@@ -142,6 +148,9 @@ gst_inference_base_overlay_class_init (GstInferenceBaseOverlayClass * klass)
142148
g_param_spec_enum ("style", "style",
143149
"Line style to draw the bounding box", LINE_STYLE_BOUNDING_BOX,
144150
DEFAULT_STYLE, G_PARAM_READWRITE));
151+
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));
145154

146155
base_transform_class->start =
147156
GST_DEBUG_FUNCPTR (gst_inference_base_overlay_start);
@@ -163,6 +172,7 @@ gst_inference_base_overlay_init (GstInferenceBaseOverlay * inference_overlay)
163172
priv->labels_list = DEFAULT_LABELS;
164173
priv->num_labels = DEFAULT_NUM_LABELS;
165174
priv->style = DEFAULT_STYLE;
175+
priv->alpha_overlay = DEFAULT_ALPHA_OVERLAY;
166176
}
167177

168178
void
@@ -205,6 +215,11 @@ gst_inference_base_overlay_set_property (GObject * object, guint property_id,
205215
GST_DEBUG_OBJECT (inference_overlay, "Changed box style to %d",
206216
priv->style);
207217
break;
218+
case PROP_ALPHA_OVERLAY:
219+
priv->alpha_overlay = g_value_get_double (value);
220+
GST_DEBUG_OBJECT (inference_overlay, "Changed overlay transparency to %lf",
221+
priv->alpha_overlay);
222+
break;
208223
default:
209224
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
210225
break;
@@ -235,6 +250,9 @@ gst_inference_base_overlay_get_property (GObject * object, guint property_id,
235250
case PROP_STYLE:
236251
g_value_set_enum (value, priv->style);
237252
break;
253+
case PROP_ALPHA_OVERLAY:
254+
g_value_set_double (value, priv->alpha_overlay);
255+
break;
238256
default:
239257
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
240258
break;
@@ -351,7 +369,7 @@ gst_inference_base_overlay_transform_frame_ip (GstVideoFilter * trans,
351369
ret =
352370
io_class->process_meta (inference_overlay, cv_mat, frame, meta,
353371
priv->font_scale, priv->thickness, priv->labels_list, priv->num_labels,
354-
priv->style);
372+
priv->style, priv->alpha_overlay);
355373

356374
out:
357375
return ret;

gst-libs/gst/opencv/gstinferencebaseoverlay.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ struct _GstInferenceBaseOverlayClass
5959

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

6465
GType meta_type;
6566
};

0 commit comments

Comments
 (0)