NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/ds3d/dataloader/depthsource/depth_source_config.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-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_DATALOADER_DEPTHSOURCE_CONFIG_H
19 #define _DS3D_DATALOADER_DEPTHSOURCE_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 namespace ds3d { namespace impl { namespace depthsource {
27 
28 constexpr const char* kDepthStream = "depth";
29 constexpr const char* kColorStream = "color";
30 
31 struct Config {
33  std::string depthSource;
34  std::string colorSource;
35  double depthScale = 1.0f;
37  Frame2DPlane depthPlane = {640, 480, 0, sizeof(uint16_t), 0};
38 
40  Frame2DPlane colorPlane = {1920, 1080, 0, sizeof(vec4b), 0};
41 
45  bool depthIntrinIsSet = false;
46  bool colorIntrinIsSet = false;
47  bool depth2ColorExSet = false;
48 
49  bool hasDepthSource() const { return !colorSource.empty(); }
50  bool hasColorSource() const { return !depthSource.empty(); }
51 };
52 
53 inline ErrCode
54 parseConfig(const std::string& content, const std::string& path, Config& config)
55 {
57  config::parseComponentConfig(content, path, config.compConfig),
58  "parse depthsource component content failed");
59 
60  YAML::Node node = YAML::Load(config.compConfig.configBody);
61  if (node["depth_source"]) {
62  config.depthSource = node["depth_source"].as<std::string>();
63  ;
64  }
65  if (node["color_source"]) {
66  config.colorSource = node["color_source"].as<std::string>();
67  ;
68  }
69 
71  !config.depthSource.empty() || !config.colorSource.empty(), ErrCode::kConfig,
72  "depth_source and color_source, at least of them must be configured");
73 
74  if (node["depth_scale"]) {
75  config.depthScale = node["depth_scale"].as<double>();
76  }
77 
78  if (node["depth_datatype"]) {
79  auto type = node["depth_datatype"].as<std::string>();
81  type == "uint16" || type == "int16", ErrCode::kConfig, "depth_datatype must be uint16");
82  }
83 
84  if (node["color"]) {
85  auto color = node["color"].as<std::string>();
86  DS3D_THROW_ERROR(color == "rgba", ErrCode::kConfig, "color must be rgba");
87  }
88  if (node["depth_size"]) {
89  auto size = node["depth_size"].as<std::vector<uint32_t>>();
90  DS3D_THROW_ERROR(size.size() == 2, ErrCode::kConfig, "depth_size must be [width, height]");
91  config.depthPlane.width = size[0];
92  config.depthPlane.height = size[1];
93  config.depthPlane.bytesPerPixel = sizeof(uint16_t);
95  }
96 
97  if (node["color_size"]) {
98  auto size = node["color_size"].as<std::vector<uint32_t>>();
99  DS3D_THROW_ERROR(size.size() == 2, ErrCode::kConfig, "color_size must be [width, height]");
100  config.colorPlane.width = size[0];
101  config.colorPlane.height = size[1];
102  config.colorPlane.bytesPerPixel = sizeof(vec4b);
104  }
105 
106  auto parseIntrinsic = [&](YAML::Node n, IntrinsicsParam& intrinsic) {
107  DS_ASSERT(bool(n));
108  intrinsic.width = n["width"].as<uint32_t>();
109  intrinsic.height = n["height"].as<uint32_t>();
110  intrinsic.centerX = n["centerX"].as<float>();
111  intrinsic.centerY = n["centerY"].as<float>();
112  intrinsic.fx = n["fx"].as<float>();
113  intrinsic.fy = n["fy"].as<float>();
114  };
115 
116  if (node["depth_intrinsic"]) {
117  parseIntrinsic(node["depth_intrinsic"], config.depthIntrinsics);
118  config.depthIntrinIsSet = true;
119  }
120  if (node["color_intrinsic"]) {
121  parseIntrinsic(node["color_intrinsic"], config.colorIntrinsics);
122  config.colorIntrinIsSet = true;
123  }
124 
125  if (node["depth_to_color_extrinsic"]) {
126  auto yExt = node["depth_to_color_extrinsic"];
127  auto r = yExt["rotation"].as<std::vector<float>>();
129  r.size() == 9, ErrCode::kConfig,
130  "depth_to_color_extrinsic.rotation must be specified as 9 float values");
131  array2Vec3<float>(&r[0], config.d2cExtrinsics.rotation[0]);
132  array2Vec3<float>(&r[3], config.d2cExtrinsics.rotation[1]);
133  array2Vec3<float>(&r[6], config.d2cExtrinsics.rotation[2]);
134  auto tr = yExt["translation"].as<std::vector<float>>();
136  tr.size() == 3, ErrCode::kConfig,
137  "depth_to_color_extrinsic.translation must be specified as 3 float values");
138  config.depth2ColorExSet = true;
139  }
140  return ErrCode::kGood;
141 }
142 
143 }}} // namespace ds3d::impl::depthsource
144 
145 #endif // _DS3D_DATALOADER_DEPTHSOURCE_CONFIG_H
ds3d::Frame2DPlane::pitchInBytes
uint32_t pitchInBytes
Definition: includes/ds3d/common/abi_frame.h:50
ds3d::impl::depthsource::Config::d2cExtrinsics
ExtrinsicsParam d2cExtrinsics
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:44
ds3d::Frame2DPlane::width
uint32_t width
Definition: includes/ds3d/common/abi_frame.h:48
ds3d::Frame2DPlane::height
uint32_t height
Definition: includes/ds3d/common/abi_frame.h:49
ds3d::DataType
DataType
Definition: includes/ds3d/common/idatatype.h:82
ds3d::Frame2DPlane
Definition: includes/ds3d/common/abi_frame.h:47
ds3d::impl::depthsource::Config::hasDepthSource
bool hasDepthSource() const
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:49
ds3d::IntrinsicsParam
Definition: includes/ds3d/common/idatatype.h:134
ds3d::Frame2DPlane::bytesPerPixel
uint32_t bytesPerPixel
Definition: includes/ds3d/common/abi_frame.h:51
ds3d::impl::depthsource::kColorStream
constexpr const char * kColorStream
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:29
ds3d::ErrCode::kGood
@ kGood
ds3d::impl::depthsource::Config
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:31
ds3d::impl::depthsource::Config::depthIntrinIsSet
bool depthIntrinIsSet
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:45
ds3d::impl::depthsource::kDepthStream
constexpr const char * kDepthStream
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:28
ds3d::impl::depthsource::Config::colorType
FrameType colorType
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:39
ds3d::impl::depthsource::Config::depthSource
std::string depthSource
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:33
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::depthsource::Config::depthIntrinsics
IntrinsicsParam depthIntrinsics
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:42
ds3d::ExtrinsicsParam::rotation
vec3f rotation[3]
Definition: includes/ds3d/common/idatatype.h:145
ds3d::impl::depthsource::Config::depthScale
double depthScale
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:35
ds3d::impl::depthsource::Config::depth2ColorExSet
bool depth2ColorExSet
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:47
pydeepstreamdoc::tensor::TensorDoc::size
constexpr const char * size
Definition: service-maker/sources/python/src/bindings/docstrings/tensordoc.h:46
ds3d::FrameType::kColorRGBA
@ kColorRGBA
ds3d::ErrCode::kConfig
@ kConfig
ds3d::impl::depthsource::Config::depthPlane
Frame2DPlane depthPlane
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:37
ds3d::DataType::kUint16
@ kUint16
ds3d::config::ComponentConfig::configBody
std::string configBody
Definition: includes/ds3d/common/config.h:48
ds3d::impl::depthsource::Config::compConfig
config::ComponentConfig compConfig
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:32
ds3d::impl::depthsource::Config::colorPlane
Frame2DPlane colorPlane
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:40
DS3D_ERROR_RETURN
#define DS3D_ERROR_RETURN(code, fmt,...)
Definition: includes/ds3d/common/defines.h:77
ds3d::impl::depthsource::Config::colorIntrinIsSet
bool colorIntrinIsSet
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:46
ds3d::impl::depthsource::Config::colorIntrinsics
IntrinsicsParam colorIntrinsics
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:43
ds3d::impl::depthsource::Config::colorSource
std::string colorSource
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:34
ds3d::ExtrinsicsParam
Definition: includes/ds3d/common/idatatype.h:144
ds3d::config::ComponentConfig
Definition: includes/ds3d/common/config.h:38
ds3d::impl::depthsource::parseConfig
ErrCode parseConfig(const std::string &content, const std::string &path, Config &config)
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:54
ds3d::FrameType
FrameType
Definition: includes/ds3d/common/idatatype.h:95
DS3D_THROW_ERROR
#define DS3D_THROW_ERROR(statement, code, msg)
Definition: includes/ds3d/common/defines.h:83
ds3d::impl::depthsource::Config::depthDataType
DataType depthDataType
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:36
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
DS_ASSERT
#define DS_ASSERT(...)
Definition: includes/ds3d/common/defines.h:36
ds3d::impl::depthsource::Config::hasColorSource
bool hasColorSource() const
Definition: sources/libs/ds3d/dataloader/depthsource/depth_source_config.h:50
ds3d::vec4b
vec4< uint8_t > vec4b
Definition: includes/ds3d/common/idatatype.h:76