1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
3 @page freespace_usecase1 Freespace Perception Workflow
4 @note SW Release Applicability: This tutorial is applicable to modules in **NVIDIA DRIVE Software** releases.
6 The following code snippet shows the general structure of a program that uses the free space detector to detect drive-able free space from a single camera. Note that error handling is left out for clarity.
8 ### Free Space Module Initialization
10 Free space detector module initialization takes an OpenRoadNet module handle as input:
13 dwStatus dwOpenRoadNet_initialize(dwOpenRoadNetHandle_t *openRoadNetHandle,
14 dwContextHandle_t ctx,
15 const dwOpenRoadNetParams *openRoadNetParams);
19 With the initialized OpenRoadNet module handle, free space module is initialized by:
22 dwStatus dwFreespaceDetector_initializeFromOpenRoadNet_new(dwFreespaceDetectorHandle_t* obj,
23 const dwFreespaceDetectorInitParams* initParams,
24 dwContextHandle_t ctx);
27 where dwFreespaceDetectorInitParams stores the initialization parameters used to initialize a free space detector module. Parameters such as the handle to a calibrated camera and cuda stream should be assigned here. Set calibrated camera handle to nullptr, to get free space boundary only in image space. You can also provide the runtime parameters via ```dwFreespaceDetectorRuntimeParams``` altogether by dwFreespaceDetector_setRuntimeParams() or individual set parameter functions described below.
29 To perform free space detection on a batch of images, you will need to set batchSize in ```dwOpenRoadNetParams``` to one of the ```dwOpenRoadNetBatchSize``` enum values before dwOpenRoadNet_initialize(). Next, the input image array needs to be bound by:
32 dwStatus dwFreespaceDetector_bindInput(const dwImageCUDA* const* frames, uint32_t frameCount, dwFreespaceDetectorHandle_t obj);
36 and output dwFreeSpaceDetection array is bound by:
39 dwStatus dwFreespaceDetector_bindOutput(dwFreespaceDetection* boundary, uint32_t frameIdx, dwFreespaceDetectorHandle_t obj);
43 where ```frameIdx``` corresponds to the frame index of the boundary to be bound.
46 ### Calibrated Camera Initialization (Optional)
48 To get free space boundary detected in top-view vehicle coordinate system, camera intrinsics can be set via the module initialization call. Note that dwFreespaceDetector_setCameraHandle(...) is deprecated. To set camera extrinsics:
51 dwFreespaceDetector_setCameraExtrinsics(dwTransformation3f cam2rig, dwFreespaceDetectorHandle_t obj);
54 ### Detector Parameter Setup (Optional)
56 Free space detector allows user to set detection Region of Interest (ROI) and how much each detected boundary is being spatially and/or temporally smoothed.
58 To set detection ROI in input image coordinates:
61 dwFreespaceDetector_setDetectionROI(const dwRect* roi,
62 dwFreespaceDetectorHandle_t obj);
65 To spatially smooth each detected free space boundary:
68 dwFreespaceDetector_setSpatialSmoothFilterWidth(uint32_t width, dwFreespaceDetectorHandle_t obj);
71 To temporally smooth each detected free space boundary:
74 dwFreespaceDetector_setTemporalSmoothFactor(float32_t factor, dwFreespaceDetectorHandle_t obj);
77 To set all the aforementioned runtime parameters at once:
80 dwStatus dwFreespaceDetector_setRuntimeParams(const dwFreespaceDetectorRuntimeParams* rtParams,
81 dwFreespaceDetectorHandle_t obj);
84 For more details, please refer to API header documentation.
87 ### Free Space Detection Execution
89 After module initialization and detector parameter setup, there are 2 options can be used to infer free space boundary on GPU and post-process on CPU:
90 For batch or single image free space boundary computation, use the following 3-stage process calls in the order of:
93 dwFreespaceDetector_process(DW_FREESPACE_DETECTOR_STAGE_GPU_ASYNC_PREPROCESSING, dwFreespaceDetectorHandle_t obj));
94 dwFreespaceDetector_process(DW_FREESPACE_DETECTOR_STAGE_GPU_ASYNC_INFERENCE, dwFreespaceDetectorHandle_t obj));
95 dwFreespaceDetector_process(DW_FREESPACE_DETECTOR_STAGE_CPU_POSTPROCESSING, dwFreespaceDetectorHandle_t obj));
98 The process calls assume that input image array and output dwFreeSpaceDetection array are bound during initialization. Then, the result can be accessed from the output dwFreeSpaceDetection array.
100 Alternatively, to process only one image at a time, use:
103 dwStatus dwFreespaceDetector_detectBoundary(dwFreespaceDetection* boundary,
104 const dwImageCUDA* frame,
105 dwFreespaceDetectorHandle_t obj);
108 instead. Input and output bindings are not required here.
110 Note that the following APIs are already deprecated and will be removed in the next release:
113 dwStatus dwFreespaceDetector_processDeviceAsync(const dwImageCUDA* frame, dwFreespaceDetectorHandle_t obj);
114 dwStatus dwFreespaceDetector_interpretHost(dwFreespaceDetectorHandle_t obj);
115 dwStatus dwFreespaceDetector_getBoundaryDetection(dwFreespaceDetection* boundary, dwFreespaceDetectorHandle_t obj);
118 ### Free Space Module Release
120 To release the free space module, the module itself needs to be released first by:
123 dwFreespaceDetector_release(dwFreespaceDetectorHandle_t *obj);
126 then the OpenRoadNet module:
129 dwOpenRoadNet_release(dwOpenRoadNetHandle_t *obj);
132 For more detailed workflow, please refer to the free space sample: @ref dwx_freespace_detection_sample