Back to Jetson Inference

Jetson Inference: jetson

docs/html/depthNet_8h_source.html

latest23.8 KB
Original Source

| | Jetson Inference

DNN Vision Library |

depthNet.h

Go to the documentation of this file.

1 /*

2 * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.

3 *

4 * Permission is hereby granted, free of charge, to any person obtaining a

5 * copy of this software and associated documentation files (the "Software"),

6 * to deal in the Software without restriction, including without limitation

7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,

8 * and/or sell copies of the Software, and to permit persons to whom the

9 * Software is furnished to do so, subject to the following conditions:

10 *

11 * The above copyright notice and this permission notice shall be included in

12 * all copies or substantial portions of the Software.

13 *

14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

20 * DEALINGS IN THE SOFTWARE.

21 */

22

23 #ifndef __DEPTH_NET_H__

24 #define __DEPTH_NET_H__

25

26 #include "tensorNet.h"

27 #include <jetson-utils/cudaColormap.h>

28

29

34 #define DEPTHNET_DEFAULT_INPUT "input_0"

35

40 #define DEPTHNET_DEFAULT_OUTPUT "output_0"

41

46 #define DEPTHNET_MODEL_TYPE "monodepth"

47

52 #define DEPTHNET_USAGE_STRING "depthNet arguments: \n" \

53 " --network NETWORK pre-trained model to load, one of the following:\n" \

54 " * fcn-mobilenet\n" \

55 " * fcn-resnet18\n" \

56 " * fcn-resnet50\n" \

57 " --model MODEL path to custom model to load (onnx)\n" \

58 " --input_blob INPUT name of the input layer (default is '" DEPTHNET_DEFAULT_INPUT "')\n" \

59 " --output_blob OUTPUT name of the output layer (default is '" DEPTHNET_DEFAULT_OUTPUT "')\n" \

60 " --profile enable layer profiling in TensorRT\n\n"

61

62

67 class depthNet : public tensorNet

68 {

69 public:

73enum VisualizationFlags

74 {

75VISUALIZE_INPUT = (1 << 0),

76VISUALIZE_DEPTH = (1 << 1),

77 };

78

83static uint32_t VisualizationFlagsFromStr( const char* str, uint32_t default_value=VISUALIZE_INPUT|VISUALIZE_DEPTH );

84

89static depthNet* Create( const char* network="fcn-mobilenet",

90 uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE,

91precisionType precision=TYPE_FASTEST,

92deviceType device=DEVICE_GPU, bool allowGPUFallback=true );

93

103static depthNet* Create( const char* model_path,

104const char* input=DEPTHNET_DEFAULT_INPUT,

105const char* output=DEPTHNET_DEFAULT_OUTPUT,

106 uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE,

107precisionType precision=TYPE_FASTEST,

108deviceType device=DEVICE_GPU, bool allowGPUFallback=true );

109

118static depthNet* Create( const char* model_path, const char* input,

119const Dims3& inputDims, const char* output,

120 uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE,

121precisionType precision=TYPE_FASTEST,

122deviceType device=DEVICE_GPU, bool allowGPUFallback=true );

123

127static depthNet* Create( int argc, char** argv );

128

132static depthNet* Create( const commandLine& cmdLine );

133

137static inline const char* Usage() { return DEPTHNET_USAGE_STRING; }

138

142virtual ~depthNet();

143

148template<typename T> bool Process( T* image, uint32_t width, uint32_t height ) { return Process((void*)image, width, height, imageFormatFromType<T>()); }

149

154bool Process( void* input, uint32_t width, uint32_t height, imageFormat format );

155

160template<typename T1, typename T2>

161bool Process( T1* input, T2* output, uint32_t width, uint32_t height,

162cudaColormapType colormap=COLORMAP_VIRIDIS_INVERTED,

163cudaFilterMode filter=FILTER_LINEAR ) { return Process((void*)input, imageFormatFromType<T1>(), (void*)output, imageFormatFromType<T2>(), width, height, colormap, filter); }

164

169bool Process( void* input, imageFormat input_format,

170void* output, imageFormat output_format,

171 uint32_t width, uint32_t height,

172cudaColormapType colormap=COLORMAP_VIRIDIS_INVERTED,

173cudaFilterMode filter=FILTER_LINEAR );

174

179template<typename T1, typename T2>

180bool Process( T1* input, uint32_t input_width, uint32_t input_height,

181 T2* output, uint32_t output_width, uint32_t output_height,

182cudaColormapType colormap=COLORMAP_DEFAULT,

183cudaFilterMode filter=FILTER_LINEAR ) { return Process((void*)input, input_width, input_height, imageFormatFromType<T1>(), (void*)output, output_width, output_height, imageFormatFromType<T2>(), colormap, filter); }

184

189bool Process( void* input, uint32_t input_width, uint32_t input_height, imageFormat input_format,

190void* output, uint32_t output_width, uint32_t output_height, imageFormat output_format,

191cudaColormapType colormap=COLORMAP_DEFAULT,

192cudaFilterMode filter=FILTER_LINEAR );

193

198template<typename T>

199bool Visualize( T* output, uint32_t width, uint32_t height,

200cudaColormapType colormap=COLORMAP_DEFAULT,

201cudaFilterMode filter=FILTER_LINEAR ) { return Visualize((void*)output, width, height, imageFormatFromType<T>(), colormap, filter); }

202

207bool Visualize( void* output, uint32_t width, uint32_t height, imageFormat format,

208cudaColormapType colormap=COLORMAP_DEFAULT,

209cudaFilterMode filter=FILTER_LINEAR );

210

214inline float* GetDepthField() const { return mOutputs[0].CUDA; }

215

219inline uint32_t GetDepthFieldWidth() const { return DIMS_W(mOutputs[0].dims); }

220

224inline uint32_t GetDepthFieldHeight() const { return DIMS_H(mOutputs[0].dims); }

225

230bool SavePointCloud( const char* filename );

231

236bool SavePointCloud( const char* filename, float* rgba, uint32_t width, uint32_t height );

237

242bool SavePointCloud( const char* filename, float* rgba, uint32_t width, uint32_t height,

243const float2& focalLength, const float2& principalPoint );

244

249bool SavePointCloud( const char* filename, float* rgba, uint32_t width, uint32_t height,

250const float intrinsicCalibration[3][3] );

251

256bool SavePointCloud( const char* filename, float* rgba, uint32_t width, uint32_t height,

257const char* intrinsicCalibrationPath );

258

259 protected:

260depthNet();

261

262bool allocHistogramBuffers();

263bool histogramEqualization();

264bool histogramEqualizationCUDA();

265

266 int2* mDepthRange;

267float* mDepthEqualized;

268 uint32_t* mHistogram;

269float* mHistogramPDF;

270float* mHistogramCDF;

271 uint32_t* mHistogramEDU;

272

274 #define DEPTH_FLOAT_TO_INT 1000000

275

277 #define DEPTH_HISTOGRAM_BINS 256

278 };

279

280

282

283 #endif

284

DEPTHNET_DEFAULT_OUTPUT

#define DEPTHNET_DEFAULT_OUTPUT

Name of default output blob for depthNet model.

Definition: depthNet.h:40

depthNet::~depthNet

virtual ~depthNet()

Destroy.

depthNet::histogramEqualization

bool histogramEqualization()

depthNet::Process

bool Process(T1 *input, T2 *output, uint32_t width, uint32_t height, cudaColormapType colormap=COLORMAP_VIRIDIS_INVERTED, cudaFilterMode filter=FILTER_LINEAR)

Process an RGB/RGBA image and map the depth image with the specified colormap.

Definition: depthNet.h:161

DEPTHNET_USAGE_STRING

#define DEPTHNET_USAGE_STRING

Command-line options able to be passed to depthNet::Create()

Definition: depthNet.h:52

depthNet::mDepthEqualized

float * mDepthEqualized

Definition: depthNet.h:267

FILTER_LINEAR

@ FILTER_LINEAR

Bilinear filtering.

Definition: cudaFilterMode.h:38

depthNet::SavePointCloud

bool SavePointCloud(const char *filename)

Extract and save the point cloud to a PCD file (depth only).

depthNet::mHistogramPDF

float * mHistogramPDF

Definition: depthNet.h:269

COLORMAP_VIRIDIS_INVERTED

@ COLORMAP_VIRIDIS_INVERTED

Viridis colormap (inverted), see http://bids.github.io/colormap/.

Definition: cudaColormap.h:52

depthNet::GetDepthFieldHeight

uint32_t GetDepthFieldHeight() const

Return the height of the depth field.

Definition: depthNet.h:224

depthNet::VisualizationFlagsFromStr

static uint32_t VisualizationFlagsFromStr(const char *str, uint32_t default_value=VISUALIZE_INPUT|VISUALIZE_DEPTH)

Parse a string of one of more VisualizationMode values.

depthNet::mHistogramEDU

uint32_t * mHistogramEDU

Definition: depthNet.h:271

depthNet::mHistogramCDF

float * mHistogramCDF

Definition: depthNet.h:270

depthNet::Process

bool Process(T *image, uint32_t width, uint32_t height)

Compute the depth field from a monocular RGB/RGBA image.

Definition: depthNet.h:148

DEVICE_GPU

@ DEVICE_GPU

GPU (if multiple GPUs are present, a specific GPU can be selected with cudaSetDevice()

Definition: tensorNet.h:131

Dims3

nvinfer1::Dims3 Dims3

Definition: tensorNet.h:58

depthNet::allocHistogramBuffers

bool allocHistogramBuffers()

COLORMAP_DEFAULT

@ COLORMAP_DEFAULT

Definition: cudaColormap.h:60

depthNet::Visualize

bool Visualize(T *output, uint32_t width, uint32_t height, cudaColormapType colormap=COLORMAP_DEFAULT, cudaFilterMode filter=FILTER_LINEAR)

Visualize the raw depth field into a colorized RGB/RGBA depth map.

Definition: depthNet.h:199

deviceType

deviceType

Enumeration for indicating the desired device that the network should run on, if available in hardwar...

Definition: tensorNet.h:129

depthNet::GetDepthField

float * GetDepthField() const

Return the raw depth field.

Definition: depthNet.h:214

depthNet::VISUALIZE_DEPTH

@ VISUALIZE_DEPTH

Display the colorized depth field.

Definition: depthNet.h:76

DEPTHNET_DEFAULT_INPUT

#define DEPTHNET_DEFAULT_INPUT

Name of default input blob for depthNet model.

Definition: depthNet.h:34

tensorNet.h

DIMS_H

#define DIMS_H(x)

Definition: tensorNet.h:61

TYPE_FASTEST

@ TYPE_FASTEST

The fastest detected precision should be use (i.e.

Definition: tensorNet.h:105

depthNet::Process

bool Process(T1 *input, uint32_t input_width, uint32_t input_height, T2 *output, uint32_t output_width, uint32_t output_height, cudaColormapType colormap=COLORMAP_DEFAULT, cudaFilterMode filter=FILTER_LINEAR)

Process an RGB/RGBA image and map the depth image with the specified colormap.

Definition: depthNet.h:180

depthNet::depthNet

depthNet()

cudaFilterMode

cudaFilterMode

Enumeration of interpolation filtering modes.

Definition: cudaFilterMode.h:35

depthNet::VISUALIZE_INPUT

@ VISUALIZE_INPUT

Display the original input image.

Definition: depthNet.h:75

depthNet::Create

static depthNet * Create(const char *network="fcn-mobilenet", uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)

Load a pre-trained model.

depthNet::Usage

static const char * Usage()

Usage string for command line arguments to Create()

Definition: depthNet.h:137

precisionType

precisionType

Enumeration for indicating the desired precision that the network should run in, if available in hard...

Definition: tensorNet.h:102

depthNet

Mono depth estimation from monocular images, using TensorRT.

Definition: depthNet.h:67

tensorNet

Abstract class for loading a tensor network with TensorRT.

Definition: tensorNet.h:218

cudaColormap.h

DIMS_W

#define DIMS_W(x)

Definition: tensorNet.h:62

depthNet::mDepthRange

int2 * mDepthRange

Definition: depthNet.h:266

cudaColormapType

cudaColormapType

Enumeration of built-in colormaps.

Definition: cudaColormap.h:36

DEFAULT_MAX_BATCH_SIZE

#define DEFAULT_MAX_BATCH_SIZE

Default maximum batch size.

Definition: tensorNet.h:88

commandLine

Command line parser for extracting flags, values, and strings.

Definition: commandLine.h:35

depthNet::mHistogram

uint32_t * mHistogram

Definition: depthNet.h:268

depthNet::histogramEqualizationCUDA

bool histogramEqualizationCUDA()

imageFormat

imageFormat

The imageFormat enum is used to identify the pixel format and colorspace of an image.

Definition: imageFormat.h:49

depthNet::VisualizationFlags

VisualizationFlags

Visualization flags.

Definition: depthNet.h:73

tensorNet::mOutputs

std::vector< layerInfo > mOutputs

Definition: tensorNet.h:819

depthNet::GetDepthFieldWidth

uint32_t GetDepthFieldWidth() const

Return the width of the depth field.

Definition: depthNet.h:219