DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

imageprocessing/motion/denseopticalflow/docs/usecase1.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page denseopticalflow_usecase1 Dense Optical Flow Workflow
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
6 
7 #### Initialization
8 
9 NVIDIA<sup>&reg;</sup> DriveWorks includes a sample pipeline demonstrating the Dense Optical Flow module across multiple video frames. The following summarizes the sample's initialization steps:
10 
11 Initialize the parameters for the module with default values:
12 
13 ```{.cpp}
14  dwDenseOpticalFlowParameters params;
15  dwDenseOpticalFlow_initDefaultParams(&params);
16 ```
17 
18 Select the processors for the corresponding stages to run on:
19 
20 ```{.cpp}
21  params.processorNVENC = DW_PROCESSOR_TYPE_NVENC_0;
22  params.processorPVA = DW_PROCESSOR_TYPE_PVA_0;
23 ```
24 
25 Set input image size dimensions:
26 
27 ```{.cpp}
28  params.imageWidth = 1280;
29  params.imageHeight = 800;
30 ```
31 
32 Initialize the Dense Optical Flow module:
33 
34 ```{.cpp}
35  dwDenseOpticalFlowHandle_t dof;
36  dwDenseOpticalFlow_initialize(&dof, &params, sdk);
37 ```
38 
39 Finally, the output image must be allocated by the application. This can be achieved by acquiring the required properties and
40 using the dwImage API:
41 
42 ```{.cpp}
43  dwImageProperties outputProperties;
44  dwDenseOpticalFlow_getOutputImageProperties(&outputProperties, dof);
45 
46  dwImageHandle_t outputImage;
47  dwImage_create(&imageOutput, outputProperties, sdk);
48 ```
49 
50 #### Process
51 
52 DriveWorks accepts two images as input: a reference image, and a template image. These two are used to compute the motion vectors.
53 
54 The input images must have the following format: `::DW_IMAGE_FORMAT_YUV420_UINT8_SEMIPLANAR`.
55 
56 The output image has the following format: `::DW_IMAGE_FORMAT_RG_INT16. The R and G channels represent motion in the X and Y dimensions, respectively.
57 
58 ```{.cpp}
59  dwDenseOpticalFlow_calculateOpticalFlow(outputImage,
60  imageYUV420,
61  imageRefYUV420,
62  dof);
63 ```
64 
65 #### Release
66 
67 Finally, release the resources used:
68 
69 ```{.cpp}
70  dwImage_destroy(imageOutput);
71  dwDenseOpticalFlow_release(dof);
72 ```
73 
74 For a demonstration of this workflow, see @ref dwx_denseopticalflow_sample.