@@ -54,6 +54,7 @@ static const cv::Scalar colors[] = {
54
54
#define CHOSEN_COLOR 14
55
55
#define OVERLAY_HEIGHT 50
56
56
#define OVERLAY_WIDTH 30
57
+ #define OVERLAY_X_POSITION 0
57
58
#define LINES_GAP 20
58
59
59
60
GST_DEBUG_CATEGORY_STATIC (gst_inference_overlay_debug_category);
@@ -67,7 +68,7 @@ static void gst_inference_overlay_get_property (GObject * object,
67
68
static GstFlowReturn gst_inference_overlay_process_meta (GstInferenceBaseOverlay
68
69
* inference_overlay, cv::Mat & cv_mat, GstVideoFrame * frame,
69
70
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 );
71
72
static void draw_line (cv::Mat & img, cv::Point pt1, cv::Point pt2,
72
73
cv::Scalar color, gint thickness, LineStyleBoundingBox style, gint gap);
73
74
@@ -193,7 +194,7 @@ draw_line (cv::Mat & img, cv::Point pt1, cv::Point pt2, cv::Scalar color,
193
194
static void
194
195
gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
195
196
gdouble font_scale, gint thickness, gchar ** labels_list, gint num_labels,
196
- LineStyleBoundingBox style)
197
+ LineStyleBoundingBox style, gdouble alpha_overlay )
197
198
{
198
199
cv::Size size;
199
200
cv::String label;
@@ -203,9 +204,10 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
203
204
cv::String prob;
204
205
BoundingBox box;
205
206
gint classes = 0 ;
206
- gdouble alpha = 0.5 ;
207
- cv::Mat alpha_overlay;
207
+ gdouble alpha = alpha_overlay;
208
208
gint width, height, x, y = 0 ;
209
+ cv::Size max_size = cv::Size (0 ,0 );
210
+ cv::Size current_size = cv::Size (0 ,0 );
209
211
210
212
g_return_if_fail (pred != NULL );
211
213
@@ -217,7 +219,7 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
217
219
(GstInferencePrediction *) tree_iter->data ;
218
220
219
221
gst_get_meta (predict, cv_mat, font_scale, thickness,
220
- labels_list, num_labels, style);
222
+ labels_list, num_labels, style, alpha_overlay );
221
223
}
222
224
223
225
if (!pred->enabled ) {
@@ -227,6 +229,10 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
227
229
228
230
box = pred->bbox ;
229
231
232
+ if (TRUE == G_NODE_IS_ROOT (pred->predictions )) {
233
+ box.width = 0 ;
234
+ }
235
+
230
236
for (iter = pred->classifications ; iter != NULL ; iter = g_list_next (iter)) {
231
237
GstInferenceClassification *classification = (GstInferenceClassification *)
232
238
iter->data ;
@@ -242,26 +248,28 @@ gst_get_meta (GstInferencePrediction * pred, cv::Mat & cv_mat,
242
248
label = cv::format (" Label #%d : %0.3f" , classification->class_id ,
243
249
classification->class_prob );
244
250
}
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 ,
246
252
box.y + classes * OVERLAY_WIDTH), cv::FONT_HERSHEY_PLAIN,
247
253
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,
251
255
thickness, 0 );
256
+ if (current_size.width > max_size.width ){
257
+ max_size = current_size;
258
+ }
259
+ }
252
260
253
- if ((box.x + box. width ) < 0 ) {
261
+ if ((box.x + OVERLAY_X_POSITION ) < 0 ) {
254
262
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 ) {
256
264
x = cv_mat.cols - 1 ;
257
265
} else {
258
- x = box.x + box. width ;
266
+ x = box.x + OVERLAY_X_POSITION ;
259
267
}
260
268
261
- if ((int ) (x + box. width + text .width ) >= cv_mat.cols ) {
269
+ if ((int ) (x + OVERLAY_X_POSITION + max_size .width ) >= cv_mat.cols ) {
262
270
width = cv_mat.cols - x - 1 ;
263
271
} else {
264
- width = text .width ;
272
+ width = max_size .width ;
265
273
}
266
274
267
275
if ((int ) (box.y + OVERLAY_HEIGHT * classes) >= cv_mat.rows ) {
@@ -315,7 +323,7 @@ static GstFlowReturn
315
323
gst_inference_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
316
324
cv::Mat & cv_mat, GstVideoFrame * frame, GstMeta * meta, gdouble font_scale,
317
325
gint thickness, gchar ** labels_list, gint num_labels,
318
- LineStyleBoundingBox style)
326
+ LineStyleBoundingBox style, gdouble alpha_overlay )
319
327
{
320
328
GstInferenceMeta *detect_meta;
321
329
@@ -326,7 +334,7 @@ gst_inference_overlay_process_meta (GstInferenceBaseOverlay * inference_overlay,
326
334
detect_meta = (GstInferenceMeta *) meta;
327
335
328
336
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 );
330
338
331
339
return GST_FLOW_OK;
332
340
}
0 commit comments