DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

Parking Space Perception Workflow

The following code snippet shows the description of the API calls and the general structure of a program that uses Parking Space Perception to detect available parking spaces and their entry-lines from a single camera.

Note
Error handling is left out for clarity.

Parking Space Detector Module Initialization

The Parking Space Perception module (ParkNet-detector) initialization requires two important pieces: a ParkNet-DNN handle and a ParkNetDetector parameters structure. The ParkNet-DNN handle is initialized and obtained separately, more information on this is available on ParkNet Workflow.

The initialization ParkNetDetector parameters structure is helped with the following call:

The above call pre-populates the provided detector-parameter structure with default-values. The more specific setting of those parameters, such as camera-based extrinsics, ROI, and others need to be performed manually. It is important to populate camera-calibration parameters correctly, in order to obtain a valid 3D-world coordinate conversion for the parking spaces detected in the image space.

Once the dwParkNetDetectorParams-structure is initialized with correct values and the dwParkNetHandle is obtained through the ParkNet-DNN module, initialize the ParkNetDetector-handle with the following call:

Two additional steps are required before having an operating parking-space detection pipeline. First, the detector must be bound to the input-data source. Such binding is permanent for all subsequent inference-calls, all data is expected to be available in the source location at the time of inference. To bind an input-data source:

Lastly, output-sink must be bound for the detected parking spaces. Such binding is also permanent for all subsequent inference-calls or until another binding is performed. The output-binding is performed by the following call:

The following few snippets demonstrate the initialization example.

Initialize the ParkNet-DNN default parameters and the ParkNet-DNN module:

dwParkNetParams parkNetParams{};
dwParkNetHandle_t parkNetHandle;
dwParkNet_initDefaultParams(&parkNetParams, sdkHandle);
dwParkNet_initialize(&parkNetHandle, &parkNetParams, sdkHandle));

Initialize the ParkNet-detector parameters structure:

As a follow-up step, manually set the parameters, values for which may be different from the default. The camera calibration parameters setting is an example of a group of parameters that usually need to be adjusted manually.

detectorParams.cam = ...;
detectorParams.cam2rig = ...;

Initialize the ParkNet-detector module from the initialized ParkNet-DNN handle and the ParkNet-detector parameters structure:

dwParkNetDetectorHandle_t parkNetDetectorHandle;
&detectorParams,
parkNetHandle,
sdkHandle);

Detector Parameter Setup and Query (Optional)

The Parking Space Perception module allows you to set additional parameters during the run-time.

To set the camera's extrinsic parameters for the module with new values:

To set the CUDA-stream handle to a new value:

To check the value of the existing CUDA-stream handle:

The following snippet demonstrates how to set the camera extrinsics and the CUDA-stream.

dwParkNetDetector_setCameraExtrinsics(cam2rig, parkNetDetectorHandle);
const cudaStream_t stream;
dwParkNetDetector_setCUDAStream(stream, parkNetDetectorHandle);

Parking Space Detection Execution

After initializing the Parking Space Perception module, the sequential API calls to detect available parking spaces from an input image are as follows.

To perform network inference on the GPU:

To interpret the inferred raw network signal into parking spaces output in both 2D-image and 3D-world coordinates:

Such interpretation is performed on the CPU device.

Both calls from the above can also be performed by the standardized processing call:

Where stage flag is set to DW_PARKNET_DETECTOR_STAGE_GPU_ASYNC_INFERENCE for the GPU inference call, or DW_PARKNET_DETECTOR_STAGE_CPU_POSTPROCESSING for the CPU interpretation call. Internally, dwParkNetDetector_process just calls either dwParkNetDetector_inferDeviceAsync or dwParkNetDetector_interpret depending on the value of stage flag.

After two calls for inference and interpretation, the output-sink contains the parking-space detection results.

To copy these results to a user provided location:

The following snippet demonstrates the example of the loop-based video processing.

Note the use of setting input-data and output-sink, which can be either permanently set within the initialization stage or set per individual frame link as in this example.

while(true)
{
//optional binding of input-source
const dwImageCUDA inputSource;
dwParkDetection parkingSpaces{};
dwParkNetDetector_bindInput(&inputSource, parkNetDetectorHandle);
dwParkNetDetector_bindOutput(&parkingSpaces, parkNetDetectorHandle);
// inference and interpretation
dwParkNetDetector_inferDeviceAsync(parkNetDetectorHandle);
dwParkNetDetector_interpret(parkNetDetectorHandle);
}

Parking Space Detector Module Release

To release the resources associated with the Parking Space Perception handle:

To release the resources associated with the ParkNet DNN handle:

The following snippet demonstrates this release process:

dwParkNetDetector_release(parkNetDetectorHandle);
dwParkNet_release(parkNetHandle);

For a more detailed workflow, please refer to the parking space detection sample: Parking Space Detection Sample .