From 81051c16b68e961d03d25a8ac49e699191cf1b0f Mon Sep 17 00:00:00 2001 From: Daniel Morin Date: Tue, 5 Dec 2023 12:21:37 -0500 Subject: [PATCH] onnx: replace video-region-of-interest with analytics-meta - Use analytics-meta/OD to transport object detection results Part-of: --- .../onnx/decoders/gstssdobjectdetector.cpp | 39 ++++++++----------- .../gst-plugins-bad/ext/onnx/meson.build | 3 +- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp index 94c1ad7abe..7317ffc6b0 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp @@ -3,7 +3,7 @@ * Copyright (C) 2021 Collabora Ltd. * * gstssdobjectdetector.cpp - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either @@ -54,7 +54,8 @@ #include #include -#include + +#include #include "tensor/gsttensormeta.h" GST_DEBUG_CATEGORY_STATIC (ssd_object_detector_debug); @@ -304,6 +305,8 @@ static gboolean gst_ssd_object_detector_process (GstBaseTransform * trans, GstBuffer * buf) { GstTensorMeta *tmeta = NULL; + GstAnalyticsODMtd odmtd; + GstAnalyticsRelationMeta *rmeta; GstSsdObjectDetector *self = GST_SSD_OBJECT_DETECTOR (trans); // get all tensor metas @@ -311,6 +314,9 @@ gst_ssd_object_detector_process (GstBaseTransform * trans, GstBuffer * buf) if (!tmeta) { GST_WARNING_OBJECT (trans, "missing tensor meta"); return TRUE; + } else { + rmeta = gst_buffer_add_analytics_relation_meta (buf); + g_return_val_if_fail (rmeta != NULL, FALSE); } std::vector < GstMlBoundingBox > boxes = @@ -319,28 +325,15 @@ gst_ssd_object_detector_process (GstBaseTransform * trans, GstBuffer * buf) self->score_threshold); for (auto & b:boxes) { - auto vroi_meta = gst_buffer_add_video_region_of_interest_meta (buf, - GST_SSD_OBJECT_DETECTOR_META_NAME, - b.x0, b.y0, - b.width, - b.height); - if (!vroi_meta) { - GST_WARNING_OBJECT (trans, - "Unable to attach GstVideoRegionOfInterestMeta to buffer"); - return FALSE; - } - auto s = gst_structure_new (GST_SSD_OBJECT_DETECTOR_META_PARAM_NAME, - GST_SSD_OBJECT_DETECTOR_META_FIELD_LABEL, - G_TYPE_STRING, - b.label.c_str (), - GST_SSD_OBJECT_DETECTOR_META_FIELD_SCORE, - G_TYPE_DOUBLE, - b.score, - NULL); - gst_video_region_of_interest_meta_add_param (vroi_meta, s); - GST_DEBUG_OBJECT (self, - "Object detected with label : %s, score: %f, bound box: (%f,%f,%f,%f) \n", + if (gst_analytics_relation_meta_add_od_mtd (rmeta, + g_quark_from_string(b.label.c_str ()), b.x0, b.y0, b.width, b.height, + b.score, &odmtd)) { + GST_DEBUG_OBJECT (self, + "Object detected with label : %s, score: %f, bound box: (%f,%f,%f,%f)", b.label.c_str (), b.score, b.x0, b.y0, b.x0 + b.width, b.y0 + b.height); + } else { + GST_ERROR_OBJECT (self, "Failed to add object detection analytics-meta"); + } } return TRUE; diff --git a/subprojects/gst-plugins-bad/ext/onnx/meson.build b/subprojects/gst-plugins-bad/ext/onnx/meson.build index 06e1293c8e..f2d40006bf 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/meson.build +++ b/subprojects/gst-plugins-bad/ext/onnx/meson.build @@ -24,7 +24,8 @@ if onnxrt_dep.found() cpp_args : gst_plugins_bad_args + extra_args, link_args : noseh_link_args, include_directories : [configinc, libsinc, cuda_stubinc], - dependencies : [gstbase_dep, gstvideo_dep, onnxrt_dep, libm] + extra_deps, + dependencies : [gstbase_dep, gstvideo_dep, gstanalytics_dep, onnxrt_dep, + libm] + extra_deps, install : true, install_dir : plugins_install_dir, )