DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

image/docs/usecase2.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page image_usecase2 Image Streamer
4 @tableofcontents
5 
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 This tutorial demonstrates how to stream an image from host (CPU) memory, to device (CUDA) memory.<br>
9 
10 The ImageStreamer module is accessed through a handle:
11 
12 ```{.cpp}
13 dwImageStreamerHandle_t streamerCPU2CUDA = DW_NULL_HANDLE;
14 ```
15 @section image_usecase2_creating_image Creating an Image
16 
17 To create an image for streaming:
18 
19 ```{.cpp}
20  // the image is going to be format interleaved RGB and type UINT_8
21  dwImageProperties cpuProp{};
22  cpuProp.type = DW_IMAGE_CPU;
23  cpuProp.width = imageWidth;
24  cpuProp.height = imageHeight;
25  cpuProp.format = DW_IMAGE_FORMAT_RGB_UINT8;
26  cpuProp.memoryLayout = DW_IMAGE_MEMORY_TYPE_DEFAULT; // not necessary to specify if init with {}
27 
28  //Create an image with these properties
29  dwImageHandle_t rgbCPU;
30  dwImage_create(&rgbCPU, cpuProp, m_context);
31 ```
32 
33 @section image_usecase2_initialize Initializing the ImageStreamer Module
34 
35 Once an image is creating for streaming, an ImageStreamer must be initialized to stream the CPU image to CUDA.<br>
36 In the following example, the ::dwImageStreamerHandle_t handle initializes the ImageCapture module to stream <br> an image with `cpuProp` image properties to type ::dwImageCUDA:
37 
38 ```{.cpp}
39  // streamer from CPU to CUDA
40  dwImageStreamerHandle_t streamerCPU2CUDA = DW_NULL_HANDLE;
41 
42  dwImageStreamer_initialize(streamerCPU2CUDA, &cpuProp, DW_IMAGE_CUDA, dwContext);
43 ```
44 
45 @section image_usecase2_streaming_image Streaming the Image
46 
47 To stream the image:
48 
49 ```{cpp}
50  dwImageStreamer_producerSend(rgbCPU,streamerCPU2CUDA);
51  dwImageHandle_t rgbCUDA;
52  dwImageStreamer_consumerReceive(&rgbCUDA,streamerCPU2CUDA);
53 ```
54 
55 @section image_usecase2_return Returning the Images
56 
57 An image must be returned once streaming to CUDA memory is complete:
58 
59 ```{cpp}
60  dwImageStreamer_consumerReturn(rgbCUDA,streamerCPU2CUDA);
61  dwImageStreamer_producerReturn(rgbCPU,streamerCPU2CUDA);
62 ```
63 
64 @section image_usecase2_releasing_handle Releasing the Handle
65 
66 To release the handle:
67 
68 ```{cpp}
69  dwImageStreamer_release(streamerCPU2CUDA);
70 ```
71 
72 To see a full demonstration of this workflow, please refer to @ref dwx_image_streamer_simple_sample.