1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
3 @page stereo_usecase2 Disparity Computation Workflow on PVA and NVENC
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 This section explains how to use NVIDIA<sup>®</sup> DriveWorks Stereo PVA module to compute a disparity map from two rectified `::dwImageHandle_t` images.
9 For more information about rectifying images, see @ref stereo_usecase1.
11 ### Step 1: Initialize the stereo pva handle
12 To initialize a `::dwStereoPVAHandle_t` object, `dwStereoPVAParams` is required. To illustrate, the following example initializes stereo parameters with default values:
15 dwStereoPVAParams stereoParams{};
16 dwStereoPVA_initParams(&stereoParams);
19 And the following modifies the parameters according to application requirements:
22 // Set estimation mode to high quality.
23 stereoParams.estimationMode = DW_STEREO_PVA_MODE_HIGH_QUALITY;
24 // The PVA parts of the pipeline will run on PVA 0.
25 stereoParams.processorPVA = DW_PROCESSOR_PVA_0;
26 // The NVENC parts of the pipeline will run on NVENC 0.
27 stereoParams.processorNVENC = DW_PROCESSOR_NVENC_0;
30 For mor information regarding all available parameters, please refer to the `dwStereoPVAParams` structure.
32 @note Estimation mode affects both the computational performance and the quality of the algorithm. This should be adjusted according to the requirements of the application.
34 After initializing the stereo parameters, initialize the module as follows:
37 // initialize stereo module
38 dwStereoPVAHandle_t stereoAlgorithm;
39 dwStereoPVA_initialize(stereoAlgorithm, imageWidth, imageHeight, &stereoParams, contextHandle);
42 where `contextHandle` is assumed to be a previously initialized `::dwContextHandle_t`.
44 ### Step 2: Inputs and outputs
46 StereoPVA module expects either NvMedia or CUDA image of `DW_IMAGE_FORMAT_YUV420_UINT8_SEMIPLANAR` format as rectified input images.
48 StereoPVA module provides functions to determine the size, type and format of the outputs in order to be able to create them on the application side.
50 The properties of the outputs can be obtained by:
53 // Get image properties for disparity output
54 dwImageProperties disparityImageProperties{};
55 dwImageProperties confidenceImageProperties{};
56 dwStereoPVA_getDisparityImageProperties(&disparityImageProperties, stereoAlgorithm);
57 dwStereoPVA_getConfidenceImageProeprties(&confidenceImageProperties, stereoAlgorithm);
60 The images can be constructed with the properties:
63 dwImage_create(&disparityOutput, disparityImageProperties, contextHandle);
64 dwImage_create(&confidenceOutput, disparityImageProperties, contextHandle);
67 ### Step 3: Compute the disparity map
68 Call `dwStereoPVA_computeDisparity()` to compute the disparity map and the confidence map based on the parameters set in `dwStereoPVAParams`. The disparity is computed from left to right.
71 // Compute disparity given left and right pyramid
72 dwStereoPVA_computeDisparity(disparityMap, confidenceMap, leftRectifiedImage, rightRectifiedImage, stereoAlgorithm));
75 Disparity is defined as an 8-bit unsigned value.
76 Confidence is defines as a 16-bit unsigned value representing how reliable the associated disparity value is.
78 The disparity computation pipeline consists of multiple stages and utilizes multiple hardware engines, namely CPU, VIC (Video Image Compositor), PVA (Programmable Vision Accelerator), NVENC (Video Encoder) and GPU.
80 ### Step 4: Release the stereo algorithm
81 Finally, release the stereo rectifier and stereo algorithm as follows:
84 // Release stereo module
85 dwStereoPVA_release(stereoAlgorithm);
88 For more details see @ref dwx_stereo_disparity_pva_sample, where it is shown how to perform image rectification and disparity estimation on multiple hardware accelerators on a video pair.