NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef DS3D_DATAFILTER_SENSOR_FUSIOIN_CONFIG_H
19 #define DS3D_DATAFILTER_SENSOR_FUSIOIN_CONFIG_H
20 
21 #include <ds3d/common/common.h>
22 #include <ds3d/common/func_utils.h>
23 
24 #include "ds3d/common/hpp/yaml_config.hpp"
25 
26 #include <unordered_set>
27 
28 namespace ds3d { namespace impl { namespace filter {
29 
30 constexpr const float kDefaultIouThreshold = 0.1f;
31 
32 struct MatchLabel {
33  std::string newLabel;
34  vec4f color = {{1.0f, 1.0f, 0, 1.0f}}; // RGBA;
35  std::string label2D;
36  std::string label3D;
37 };
38 
39 using FusionLabels = std::vector<MatchLabel>;
40 
41 struct Config {
42  config::ComponentConfig compConfig;
43  std::string input2DBboxKey = kObject2DBboxKey;
44  std::string input3DbboxKey = kLidar3DBboxRawData;
45  std::string input2DImageKey; // empty means no input color image
46  std::string camIntrinsicsKey = kCamIntrinsicMat;
49  std::string outputFusedKey = kFusedDetectionKey;
50  std::string outputFusedBboxRenderKey; // disable if no value set from config file, this is for
51  // render purpose
54 };
55 
56 inline ErrCode
57 parseConfig(const std::string& content, const std::string& path, Config& config)
58 {
60  config::parseComponentConfig(content, path, config.compConfig),
61  "parse dataloader component content failed");
62  YAML::Node node = YAML::Load(config.compConfig.configBody);
63  auto yInput2DBbox = node["2d_objects_input_key"];
64  auto yInput3Dbbox = node["3d_objects_input_key"];
65  auto y2dInputColor = node["2d_color_image_input_key"];
66  auto yMatchClasses = node["match_classes"];
67  auto yCamInt = node["cam_intrinsics_mat_key"];
68  auto yCamIntParam = node["cam_intrinsics_param_key"];
69  auto yLidar2CamExt = node["lidar_to_cam_extrinsics_mat_key"];
70  auto yIouThreshold = node["iou_threshold"];
71  auto yOutputFusedKey = node["output_fused_detection_key"];
72  auto yOutputFusedRenderKey = node["output_fused_3d_bbox_key"];
73 
75  yMatchClasses, ErrCode::kConfig, "<match_classes> list is required in sensorfusion config");
76 
77  std::unordered_set<std::string> labelsCheck;
78  for (std::size_t i = 0; i < yMatchClasses.size(); i++) {
79  const YAML::Node& kvs = yMatchClasses[i];
80  for (const auto& kv : kvs) {
81  auto yMatch = kv.second;
82  auto y2D = yMatch["label_2d"];
83  auto y3D = yMatch["label_3d"];
84  auto yColor = yMatch["color"];
85 
86  MatchLabel match;
87  match.newLabel = kv.first.as<std::string>();
88  match.label2D = y2D.as<std::string>();
89  match.label3D = y3D.as<std::string>();
90  if (yColor) {
91  auto color = yColor.as<std::vector<float>>();
92  size_t size = (color.size() < 3 ? color.size() : 3);
93  for (size_t i = 0; i < size; ++i) {
94  match.color.data[i] = color[i] / 255.0f;
95  }
96  }
97  if (labelsCheck.count(match.newLabel)) {
99  "new label: %s exist multiple times in sensor fusion config, it might match "
100  "multiple labels",
101  match.newLabel.c_str());
102  } else {
103  labelsCheck.insert(match.newLabel);
104  }
105 
106  config.fusionLabels.emplace_back(match);
107  }
108  }
109 
110  if (yInput2DBbox) {
111  config.input2DBboxKey = yInput2DBbox.as<std::string>();
112  }
113  if (yInput3Dbbox) {
114  config.input3DbboxKey = yInput3Dbbox.as<std::string>();
115  }
116  if (y2dInputColor) {
117  config.input2DImageKey = y2dInputColor.as<std::string>();
118  }
119  if (yCamInt) {
120  config.camIntrinsicsKey = yCamInt.as<std::string>();
121  }
122  if (yCamIntParam) {
123  config.camIntrinsicsParamKey = yCamIntParam.as<std::string>();
124  }
125  if (yLidar2CamExt) {
126  config.lidar2CamExtrinsicsKey = yLidar2CamExt.as<std::string>();
127  }
128  if (yIouThreshold) {
129  config.iouThreshold = yIouThreshold.as<float>();
130  }
131  if (yOutputFusedKey) {
132  config.outputFusedKey = yOutputFusedKey.as<std::string>();
133  }
134  if (yOutputFusedRenderKey) {
135  config.outputFusedBboxRenderKey = yOutputFusedRenderKey.as<std::string>();
136  }
137 
138  LOG_DEBUG("fusion config, 2d_objects_input_key: %s", config.input2DBboxKey.c_str());
139  LOG_DEBUG("fusion config, 3d_objects_input_key: %s", config.input3DbboxKey.c_str());
140  std::stringstream ssKeys;
141  for (const auto& label : config.fusionLabels) {
142  ssKeys << " " << label.newLabel << ",";
143  }
144  LOG_DEBUG("fusion config, 2d_input_key:%s", ssKeys.str().c_str());
145 
146  return ErrCode::kGood;
147 }
148 
149 }}} // namespace ds3d::impl::filter
150 
151 #endif // DS3D_DATAFILTER_SENSOR_FUSIOIN_CONFIG_H
ds3d::impl::filter::MatchLabel::color
vec4f color
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:34
ds3d::kFusedDetectionKey
static constexpr const char * kFusedDetectionKey
get array of FusedDetection from FrameGuard [N, sizeof(FusedDetection)]
Definition: includes/ds3d/common/common.h:143
ds3d::impl::filter::Config::camIntrinsicsKey
std::string camIntrinsicsKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:46
ds3d::impl::filter::Config::outputFusedBboxRenderKey
std::string outputFusedBboxRenderKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:50
ds3d::impl::filter::MatchLabel::label2D
std::string label2D
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:35
ds3d::impl::filter::Config::input2DImageKey
std::string input2DImageKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:45
ds3d::vec4f
vec4< float > vec4f
Definition: includes/ds3d/common/idatatype.h:71
ds3d::impl::filter::Config::camIntrinsicsParamKey
std::string camIntrinsicsParamKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:47
ds3d::impl::filter::Config::fusionLabels
FusionLabels fusionLabels
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:53
ds3d::kLidar3DBboxRawData
static constexpr const char * kLidar3DBboxRawData
get array of Lidar3DBbox from FrameGuard [N, sizeof(Lidar3DBbox)]
Definition: includes/ds3d/common/common.h:119
LOG_DEBUG
#define LOG_DEBUG(fmt,...)
Definition: includes/ds3d/common/defines.h:59
ds3d::impl::filter::Config::input3DbboxKey
std::string input3DbboxKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:44
ds3d::impl::filter::kDefaultIouThreshold
constexpr const float kDefaultIouThreshold
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:30
ds3d::ErrCode::kGood
@ kGood
ds3d::kLidarToCamExtrinsicMat
static constexpr const char * kLidarToCamExtrinsicMat
Definition: includes/ds3d/common/common.h:124
ds3d::impl::filter::Config::outputFusedKey
std::string outputFusedKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:49
LOG_WARNING
#define LOG_WARNING(fmt,...)
Definition: includes/ds3d/common/defines.h:65
ds3d::impl::filter::Config::iouThreshold
float iouThreshold
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:52
ds3d::config::parseComponentConfig
ErrCode parseComponentConfig(const std::string &yamlComp, const std::string &path, ComponentConfig &config)
Definition: includes/ds3d/common/hpp/yaml_config.hpp:57
DS3D_FAILED_RETURN
#define DS3D_FAILED_RETURN(condition, ret, fmt,...)
Definition: includes/ds3d/common/defines.h:69
ds3d::ErrCode
ErrCode
Definition: includes/ds3d/common/common.h:47
ds3d::impl::filter::Config::lidar2CamExtrinsicsKey
std::string lidar2CamExtrinsicsKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:48
ds3d::kCamIntrinsicParm
static constexpr const char * kCamIntrinsicParm
Definition: includes/ds3d/common/common.h:122
ds3d::impl::filter::Config::compConfig
config::ComponentConfig compConfig
Definition: sources/libs/ds3d/datafilter/alignment/alignment_config.h:36
ds3d::kCamIntrinsicMat
static constexpr const char * kCamIntrinsicMat
Definition: includes/ds3d/common/common.h:123
ds3d::kObject2DBboxKey
static constexpr const char * kObject2DBboxKey
get array of Object2DBbox from FrameGuard [N, sizeof(Object2DBbox)]
Definition: includes/ds3d/common/common.h:140
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
ds3d::ErrCode::kConfig
@ kConfig
DS3D_ERROR_RETURN
#define DS3D_ERROR_RETURN(code, fmt,...)
Definition: includes/ds3d/common/defines.h:77
ds3d::impl::filter::MatchLabel::newLabel
std::string newLabel
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:33
ds3d::impl::filter::MatchLabel::label3D
std::string label3D
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:36
ds3d::impl::filter::FusionLabels
std::vector< MatchLabel > FusionLabels
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:39
ds3d::impl::filter::Config::input2DBboxKey
std::string input2DBboxKey
Definition: sources/libs/ds3d/datafilter/sensorfusion_cluster/sensorfusion_config.h:43
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
ds3d::impl::filter::parseConfig
ErrCode parseConfig(const std::string &content, const std::string &path, Config &config)
The calib file parsed here have data in row major order We read it into column major order.
Definition: sources/libs/ds3d/datafilter/alignment/alignment_config.h:87