DriveWorks SDK Reference
3.0.4260 Release
For Test and Development only

perception/safety/camera/clearsightnet/docs/clearsightnet_usecase1.md
Go to the documentation of this file.
1 # Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page clearsightnet_usecase1 ClearSightNet Workflow
4 
5 ## Initialization
6 
7 The ClearSightNet and ClearSightNetDetector modules create handles of types `dwClearSightNetHandle_t` and `dwBlindnessDetectorHandle_t` respectively. Both of these handles are owned by the application and must be released by the application when not needed anymore.
8 
9 An instance of type `dwClearSightNetParams` encodes parameters that configure the ClearSightNet module. To initialize default ClearSightNet parameters:
10 
11 ```{.cpp}
12 dwStatus dwClearSightNet_initDefaultParams(dwClearSightNetParams* clearSightNetParams);
13 ```
14 
15 To initialize a pointer to a `dwClearSightNetHandle_t` instance with default parameter values:
16 
17 ```{.cpp}
18 dwStatus dwClearSightNet_initialize(dwClearSightNetHandle_t* clearSightNetHandle,
19  const dwClearSightNetParams* clearSightNetParams,
20  dwContextHandle_t ctx);
21 ```
22 
23 An instance of type `dwBlindnessDetectorParams` encapsulates several configuration parameters and encapsulates a handle to ClearSightNet (of type `dwClearSightNetHandle_t`) that configure the BlindnessDetector module.
24 
25 To initialize in instance of `dwBlindnessDetectorParams` with default values:
26 
27 ```{.cpp}
28 dwStatus dwBlindnessDetector_initDefaultParams(dwBlindnessDetectorParams *clearSightNetDetectorParams);
29 ```
30 
31 This initializes the members `dwBlindnessDetectorParams.temporalFilterWindow`, `dwBlindnessDetectorParams.numRegionsX` and `dwBlindnessDetectorParams.numRegionsY` to 5, 1 and 1 respectively.
32 
33 To initialize a pointer to a `dwBlindnessDetectorHandle_t` instance with an initialized ClearSightNet handle and default parameter values:
34 
35 ```{.cpp}
36 dwStatus dwBlindnessDetector_initialize(dwClearSightNetDetectorHandle_t* clearSightNetDetectorHandle,
37  dwBlindnessDetectorParams *clearSightNetDetectorParams,
38  dwContextHandle_t ctx);
39 ```
40 
41 An example code snippet to initialize required modules with default values to perfrom inference on GPU:
42 
43 ```{.cpp}
44 // Initialize ClearSightNet
45 dwClearSightNetParams m_clearSightNetParams;
46 dwBlindnessDetectorParams m_detectorParams;
47 CHECK_DW_ERROR(dwClearSightNet_initDefaultParams(&m_clearSightNetParams));
48 CHECK_DW_ERROR(dwClearSightNet_initialize(&m_detectorParams.clearSightNetHandle,
49  &m_clearSightNetParams,
50  m_sdk));
51 
52 dwBlindnessDetectorHandle_t m_clearSightNetDetector;
53 CHECK_DW_ERROR(dwBlindnessDetector_initDefaultParams(&clearSightNetDetectorParams));
54 CHECK_DW_ERROR(dwBlindnessDetector_initialize(&m_clearSightNetDetector,
55  &m_detectorParams,
56  m_sdk));
57 ```
58 
59 where `m_sdk` is an initialized instance of `dwContextHandle_t`.
60 
61 Another code snippet to initialize required modules with parameters that enable 3 sub-regions in each direction:
62 
63 ```{.cpp}
64 // Initialize ClearSightNet
65 dwClearSightNetParams m_clearSightNetParams;
66 dwBlindnessDetectorParams m_detectorParams;
67 CHECK_DW_ERROR(dwClearSightNet_initDefaultParams(&m_clearSightNetParams));
68 CHECK_DW_ERROR(dwClearSightNet_initialize(&m_detectorParams.clearSightNetHandle,
69  &m_clearSightNetParams,
70  m_sdk));
71 
72 dwBlindnessDetectorHandle_t m_clearSightNetDetector;
73 CHECK_DW_ERROR(dwBlindnessDetector_initDefaultParams(&clearSightNetDetectorParams));
74 m_detectorParams.numRegionsX = 3U;
75 m_detectorParams.numRegionsY = 3U;
76 m_detectorParams.regionDividersX[0] = 0.2f; m_detectorParams.regionDividersX[1] = 0.8f;
77 m_detectorParams.regionDividersY[0] = 0.2f; m_detectorParams.regionDividersY[1] = 0.8f;
78 CHECK_DW_ERROR(dwBlindnessDetector_initialize(&m_clearSightNetDetector,
79  &m_detectorParams,
80  m_sdk));
81 ```
82 
83 Note that values for parameters `dwBlindnessDetectorParams.regionDividersX` and `dwBlindnessDetectorParams.regionDividersY` are specified in image fractions. This will create sub-region dividers at 20% and 80% of image width and height.
84 
85 ## Query Network Specs
86 
87 With initialized handle to the ClearSightNet module, the following functions can be used to query size of expected input blob, size of output blob and network metadata respectively:
88 
89 ```{.cpp}
90 dwStatus dwClearSightNet_getInputBlobSize(dwBlobSize* inputBlobsize, dwClearSightNetHandle_t clearSightNetHandle);
91 ```
92 
93 ```{.cpp}
94 dwStatus dwClearSightNet_getOutputBlobSize(dwBlobSize* outputBlobsize, dwClearSightNetHandle_t clearSightNetHandle);
95 ```
96 
97 ```{.cpp}
98 dwStatus dwClearSightNet_getDNNMetaData(dwDNNMetaData* metaData, dwClearSightNetHandle_t clearSightNetHandle);
99 ```
100 
101 ## Use for Inference
102 
103 With initialized handle to the ClearSightNetDetector module, the following functions can be used to perform inference on an image and retrieve the processed output:
104 
105 ```{.cpp}
106 dwStatus dwBlindnessDetector_detect(const dwImageCUDA* image,
107  dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
108 ```
109 
110 ```{.cpp}
111 dwStatus dwBlindnessDetector_getOutput(dwBlindnessDetectionOutput *outputs,
112  dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
113 ```
114 
115 The `dwBlindnessDetector_detect()` function performs inference asynchronously. This means that an inference call can be queued using `dwBlindnessDetector_detect()` and then other computation can be performed and `dwBlindnessDetector_getOutput()`, whenever called, will automatically wait for the inference to finish before returning the output. To this end, the following functions can be used to set and get CUDA the stream used by the module:
116 
117 ```{.cpp}
118 dwStatus dwBlindnessDetector_setCUDAStream(const cudaStream_t stream, dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
119 ```
120 
121 ```{.cpp}
122 dwStatus dwBlindnessDetector_getCUDAStream(cudaStream_t *stream, dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
123 ```
124 
125 ## Reset and Release
126 
127 The following functions can be used to reset or release the initialized module handles whenever necessary:
128 
129 ```{.cpp}
130 dwStatus dwClearSightNet_reset(dwClearSightNetHandle_t clearSightNetHandle);
131 ```
132 
133 ```{.cpp}
134 dwStatus dwClearSightNet_release(dwClearSightNetHandle_t clearSightNetHandle);
135 ```
136 
137 ```{.cpp}
138 dwStatus dwBlindnessDetector_reset(dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
139 ```
140 
141 ```{.cpp}
142 dwStatus dwBlindnessDetector_release(dwBlindnessDetectorHandle_t clearSightNetDetectorHandle);
143 ```
144 
145 For usage of a sample application, please refer to @ref dwx_clearsightnet_sample.