1515//
1616// SPDX-License-Identifier: Apache-2.0
1717
18- #include " detectnet_decoder.hpp"
19- #include " detection2_d_array_message.hpp"
20-
21- #include < string>
2218#include < climits>
19+ #include < memory>
20+ #include < string>
21+ #include < vector>
22+
23+ #include " ./detection2_d_array_message.hpp"
24+ #include " ./detectnet_decoder.hpp"
25+
26+ #include " cuda.h"
27+ #include " cuda_runtime.h"
2328
29+ #include " gxf/core/parameter_parser_std.hpp"
2430#include " gxf/multimedia/camera.hpp"
2531#include " gxf/multimedia/video.hpp"
26- #include " gxf/core/parameter_parser_std.hpp"
2732#include " gxf/std/timestamp.hpp"
28- #include " cuda.h"
29- #include " cuda_runtime.h"
3033
3134
3235namespace nvidia
@@ -67,10 +70,10 @@ NvDsInferObjectDetectionInfo GetNewDetectionInfo(
6770}
6871
6972void FillMessage (
70- Detection2DParts & message_parts,
71- const std::vector<NvDsInferObjectDetectionInfo> & detection_info_vector,
73+ Detection2DParts& message_parts,
74+ const std::vector<NvDsInferObjectDetectionInfo>& detection_info_vector,
7275 gxf::Handle<nvidia::gxf::Timestamp> tensorlist_timestamp,
73- size_t num_detections, const std::vector<std::string> & label_list)
76+ size_t num_detections, const std::vector<std::string>& label_list)
7477{
7578 for (uint32_t i = 0 ; i < num_detections; i++) {
7679 NvDsInferObjectDetectionInfo detection_info = detection_info_vector[i];
@@ -89,7 +92,7 @@ void FillMessage(
8992 }
9093 *(message_parts.timestamp ) = *tensorlist_timestamp;
9194}
92- } // anonymous namespace
95+ } // anonymous namespace
9396
9497
9598gxf_result_t DetectnetDecoder::registerInterface (gxf::Registrar * registrar) noexcept
@@ -106,8 +109,8 @@ gxf_result_t DetectnetDecoder::registerInterface(gxf::Registrar * registrar) noe
106109
107110 result &= registrar->parameter (
108111 label_list_, " label_list" , " List of network labels" ,
109- " List of labels corresponding to the int labels received from the tensors" , { " person " , " bag " ,
110- " face" });
112+ " List of labels corresponding to the int labels received from the tensors" ,
113+ { " person " , " bag " , " face" });
111114
112115 result &= registrar->parameter (
113116 enable_confidence_threshold_, " enable_confidence_threshold" , " Enable Confidence Threshold" ,
@@ -131,27 +134,27 @@ gxf_result_t DetectnetDecoder::registerInterface(gxf::Registrar * registrar) noe
131134
132135 result &= registrar->parameter (
133136 dbscan_confidence_threshold_, " dbscan_confidence_threshold" , " Dbscan Confidence Threshold" ,
134- " Minimum score in a cluster for the cluster to be considered an object \
135- during grouping. Different clustering may cause the algorithm \
136- to use different scores." ,
137+ " Minimum score in a cluster for the cluster to be considered an object "
138+ " during grouping. Different clustering may cause the algorithm "
139+ " to use different scores." ,
137140 0.6 );
138141
139142 result &= registrar->parameter (
140143 dbscan_eps_, " dbscan_eps" , " Dbscan Epsilon" ,
141- " Holds the epsilon to control merging of overlapping boxes. \
142- Refer to OpenCV groupRectangles and DBSCAN documentation for more information on epsilon. " ,
144+ " Holds the epsilon to control merging of overlapping boxes. "
145+ " Refer to OpenCV groupRectangles and DBSCAN documentation for more information on epsilon. " ,
143146 0.01 );
144147
145148 result &= registrar->parameter (
146149 dbscan_min_boxes_, " dbscan_min_boxes" , " Dbscan Minimum Boxes" ,
147- " Holds the minimum number of boxes in a cluster to be considered \
148- an object during grouping using DBSCAN" ,
150+ " Holds the minimum number of boxes in a cluster to be considered "
151+ " an object during grouping using DBSCAN" ,
149152 1 );
150153
151154 result &= registrar->parameter (
152155 dbscan_enable_athr_filter_, " dbscan_enable_athr_filter" , " Dbscan Enable Athr Filter" ,
153- " true enables the area-to-hit ratio (ATHR) filter. \
154- The ATHR is calculated as: ATHR = sqrt(clusterArea) / nObjectsInCluster." ,
156+ " true enables the area-to-hit ratio (ATHR) filter. "
157+ " The ATHR is calculated as: ATHR = sqrt(clusterArea) / nObjectsInCluster." ,
155158 0 );
156159
157160 result &= registrar->parameter (
@@ -196,7 +199,6 @@ gxf_result_t DetectnetDecoder::start() noexcept
196199
197200gxf_result_t DetectnetDecoder::tick () noexcept
198201{
199-
200202 gxf::Expected<void > result;
201203
202204 // Receive disparity image and left/right camera info
@@ -272,9 +274,10 @@ gxf_result_t DetectnetDecoder::tick() noexcept
272274 return GXF_FAILURE;
273275 }
274276
275- float bbox_tensor_arr[bbox_tensor->size () / sizeof (float )]; // since data in tensor is kFloat32
277+ // data in tensor is kFloat32
278+ std::vector<float > bbox_tensor_arr (bbox_tensor->size () / sizeof (float ));
276279 const cudaError_t cuda_error_bbox_tensor = cudaMemcpy (
277- & bbox_tensor_arr, bbox_tensor->pointer (),
280+ bbox_tensor_arr. data () , bbox_tensor->pointer (),
278281 bbox_tensor->size (), cudaMemcpyDeviceToHost);
279282 if (cuda_error_bbox_tensor != cudaSuccess) {
280283 GXF_LOG_ERROR (" Error while copying kernel: %s" , cudaGetErrorString (cuda_error_bbox_tensor));
@@ -315,8 +318,8 @@ gxf_result_t DetectnetDecoder::tick() noexcept
315318 float coverage = cov_tensor_arr[cov_pos];
316319
317320 // Center of the grid in pixels
318- float grid_center_y = (row + bounding_box_offset_ ) * kStride ;
319- float grid_center_x = (col + bounding_box_offset_ ) * kStride ;
321+ float grid_center_y = (row + bounding_box_offset_) * kStride ;
322+ float grid_center_x = (col + bounding_box_offset_) * kStride ;
320323
321324 // Get each element of the bounding box
322325 float bbox[kBoundingBoxParams ];
@@ -342,7 +345,8 @@ gxf_result_t DetectnetDecoder::tick() noexcept
342345 // check if object_class is out of range for label_list_
343346 if (static_cast <size_t >(object_class) >= label_list_.get ().size ()) {
344347 GXF_LOG_ERROR (
345- " [DetectNet Decoder] object_class %i is out of range for provided label_list_ of size %lu" , object_class,
348+ " [DetectNet Decoder] object_class %i is out of range for provided "
349+ " label_list_ of size %lu" , object_class,
346350 label_list_.get ().size ());
347351 return GXF_FAILURE;
348352 }
@@ -360,7 +364,7 @@ gxf_result_t DetectnetDecoder::tick() noexcept
360364
361365 size_t num_detections = detection_info_vector.size ();
362366 if (enable_dbscan_clustering_) {
363- NvDsInferObjectDetectionInfo * detection_info_pointer = &detection_info_vector[0 ];
367+ NvDsInferObjectDetectionInfo* detection_info_pointer = &detection_info_vector[0 ];
364368 NvDsInferDBScanHandle dbscan_hdl = NvDsInferDBScanCreate ();
365369 if (dbscan_clustering_algorithm_ == kDbscanCluster ) {
366370 NvDsInferDBScanCluster (dbscan_hdl, ¶ms_, detection_info_pointer, &num_detections);
@@ -386,7 +390,6 @@ gxf_result_t DetectnetDecoder::tick() noexcept
386390 num_detections, label_list_);
387391 return detections_transmitter_->publish (message_parts.message );
388392 }));
389-
390393}
391394} // namespace isaac_ros
392395} // namespace nvidia
0 commit comments