CUDA ISP for NVIDIA Jetson/Examples/ API usage: Difference between revisions

No edit summary
No edit summary
Tag: Manual revert
 
(45 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{CUDA ISP for NVIDIA Jetson/Head|previous=|next=|metakeywords=|metadescription=}}
{{CUDA ISP for NVIDIA Jetson/Head|previous=User Manual|next=Examples/GStreamer usage}}
 
{{#seo:
|title=CUDA ISP for NVIDIA Jetson API Usage | RidgeRun Wiki
|title_mode=replace
|description=Explore how to use CUDA ISP for NVIDIA Jetson API. Learn about setting up algorithms, creating buffers, & applying transformations.
}}
</noinclude>
</noinclude>


{{DISPLAYTITLE:CUDA ISP for NVIDIA Jetson: API usage|noerror}}
{{DISPLAYTITLE:CUDA ISP for NVIDIA Jetson API usage|noerror}}


== General ==
=== General ===


CUDA ISP provides several algorithms to process raw image data from a camera sensor in a variety of ways.
CUDA ISP provides several algorithms to process raw image data from a camera sensor in a variety of ways.


Here we illustrate a simple example that involves all the basic algorithms. This example processes a raw BAYER10 image into a I420 image with white balancing.
Here we illustrate a simple example that involves all the basic algorithms. This example processes a raw BAYER10 image into a I420 image with white balancing using the following steps:
* a
* The shift algorithm converts BAYER10 into BAYER8
* b
* The debayer algorithm converts BAYER8 to RGB
takes a raw BAYER10 image, converts it to a BAYER8 image, then converts it to a RGB image, then applies automatic white balancing on the image, then converts it to I420 format. A simple process of this type might be used to encode camera information into a video file or a network stream.
* The white balancer algorithm improves the color balance in the RGB image without changing the format
* The color space converter converts RGB to I420
 
For a detailed explanation of each algorithm, please refer to [[CUDA_ISP_for_NVIDIA_Jetson/CUDA_ISP_for_NVIDIA_Jetson_Basics]].
 
The following diagram illustrates the complete processing pipeline:


<br>
<br>
[[ File:Api usage example 4.jpeg | center ]]
[[ File:Api usage example 4.jpeg | center ]]
<br>
<br>
A simple process of this type can be used to encode camera information into a video file or a network stream.


=== Backend ===
=== Backend ===


We first create a backend object. The backend object provides factories to create algorithms and buffers. We specify CUDA as the desired backend type.
We first create a backend object. The backend object provides factories to create algorithms and buffers. For CUDA ISP, we specify CUDA as the desired backend type. All algorithms created using this backend will be CUDA accelerated.
  auto backend = rr::IBackend::Build(rr::kCUDA);
  auto backend = rr::IBackend::Build(rr::kCUDA);


Line 26: Line 39:


The creation of any given algorithm requires a single function call:
The creation of any given algorithm requires a single function call:
  auto shift = backend->CreateAlgorithm(rr::kShift);
  auto shift                 = backend->CreateAlgorithm(rr::kShift);
  auto debayer = backend->CreateAlgorithm(rr::kDebayer);
  auto debayer               = backend->CreateAlgorithm(rr::kDebayer);
  auto white_balancer = backend->CreateAlgorithm(rr::kWhiteBalancer);
  auto white_balancer       = backend->CreateAlgorithm(rr::kWhiteBalancer);
  auto color_space_converter = backend->CreateAlgorithm(rr::kColorSpaceConverter);
  auto color_space_converter = backend->CreateAlgorithm(rr::kColorSpaceConverter);


The shift object converts BAYERXX formats (BAYER10, BAYER12, BAYER14, or BAYER16) into a BAYER8 format. Each pixel in a BAYERXX format takes up 16 bits of information, but with the appropiate rightwards bit shift, the 8 most significant bits can be placed in the 8 least significant bit positions of the pixel memory. The shift object then completes the BAYERXX to BAYER8 conversion by only returning the 8 least significant bits of each pixel.
=== Creating the buffers ===
 
The image data is stored in CUDA ISP Buffers. These Buffers are used as inputs and outputs to the algorithms. Buffers can be created using the backend {{code | CreateBuffer }} method, similar to the {{code | CreateAlgorithms }} method. The {{code | CreateBuffer }} method requires the buffer size and a parameter object. In CUDA ISP, parameter objects are used to provide many methods with additional information. In this example, the parameter object used in buffer creation indicates the buffer CUDA memory type (host, device, unified or external). See [[#Parameter objects ]] for more detail.
auto bayer10_buffer        = backend->CreateBuffer(bayer10_size, buffer_params);
auto bayer8_buffer        = backend->CreateBuffer(bayer8_size,  buffer_params);
auto unbalanced_rgb_buffer = backend->CreateBuffer(rgb_size,    buffer_params);
auto balanced_rgb_buffer  = backend->CreateBuffer(rgb_size,    buffer_params);
auto i420_buffer          = backend->CreateBuffer(i420_size,    buffer_params);
 
=== Parameter objects ===
 
Parameter objects are created directly and not through a factory method. There are several different parameter objects used in different methods. The general list of parameter objects is as follows:
* ColorSpaceParams - Used to indicate whether to apply an RGB to I420 conversion or an I420 to RGB conversion during a ColorSpaceConverter application.
* CudaBufferParams - Used to indicate buffer CUDA memory type while creating a Buffer using the CUDA backend. The memory type can be Host, Device, Unified or External.
* DebayerParams - Used to indicate the input Bayer layout during a Debayer application. The Bayer layout can be RGGB, BGGR, BRGB, or BGRB.
* ShiftParams - Used to indicate the shift value during a Shift application. The shift value refers to how many bits to right-shift each input bayer pixel before converting to BAYER8.
 
This example creates a CudaBufferParams object and sets its CUDA memory type to external:
auto buffer_params = std::make_shared<CudaBufferParams>();
buffer_params->type = CudaType::kExternal;
 
=== Applying the algorithms ===
 
Each algorithm has an apply method that expects an input buffer, output buffer and parameter object.
shift->Apply(bayer10_buffer, bayer8_buffer, shift_params);
debayer->Apply(bayer8_buffer, unbalanced_rgb_buffer, debayer_params);
white_balancer->Apply(unbalanced_rgb_buffer, balanced_rgb_buffer, white_balancer_params);
color_space_converter->Apply(balanced_rgb_buffer, i420_buffer, color_space_converter_params);


The debayer object converts BAYER8 to either RGB or RGBA.
=== More information ===


You can find more examples in our [http://ridgerun.pages.ridgerun.com/rnd/libcudaisp/examples.html User Manual].


<noinclude>
<noinclude>
{{CUDA ISP for NVIDIA Jetson/Foot||}}
{{CUDA ISP for NVIDIA Jetson/Foot|User Manual|Examples/GStreamer usage}}
</noinclude>
</noinclude>

Latest revision as of 16:17, 30 September 2024



Previous: User Manual Index Next: Examples/GStreamer usage






General

CUDA ISP provides several algorithms to process raw image data from a camera sensor in a variety of ways.

Here we illustrate a simple example that involves all the basic algorithms. This example processes a raw BAYER10 image into a I420 image with white balancing using the following steps:

  • The shift algorithm converts BAYER10 into BAYER8
  • The debayer algorithm converts BAYER8 to RGB
  • The white balancer algorithm improves the color balance in the RGB image without changing the format
  • The color space converter converts RGB to I420

For a detailed explanation of each algorithm, please refer to CUDA_ISP_for_NVIDIA_Jetson/CUDA_ISP_for_NVIDIA_Jetson_Basics.

The following diagram illustrates the complete processing pipeline:


 


A simple process of this type can be used to encode camera information into a video file or a network stream.

Backend

We first create a backend object. The backend object provides factories to create algorithms and buffers. For CUDA ISP, we specify CUDA as the desired backend type. All algorithms created using this backend will be CUDA accelerated.

auto backend = rr::IBackend::Build(rr::kCUDA);

Creating the algorithms

The creation of any given algorithm requires a single function call:

auto shift                 = backend->CreateAlgorithm(rr::kShift);
auto debayer               = backend->CreateAlgorithm(rr::kDebayer);
auto white_balancer        = backend->CreateAlgorithm(rr::kWhiteBalancer);
auto color_space_converter = backend->CreateAlgorithm(rr::kColorSpaceConverter);

Creating the buffers

The image data is stored in CUDA ISP Buffers. These Buffers are used as inputs and outputs to the algorithms. Buffers can be created using the backend CreateBuffer method, similar to the CreateAlgorithms method. The CreateBuffer method requires the buffer size and a parameter object. In CUDA ISP, parameter objects are used to provide many methods with additional information. In this example, the parameter object used in buffer creation indicates the buffer CUDA memory type (host, device, unified or external). See #Parameter objects for more detail.

auto bayer10_buffer        = backend->CreateBuffer(bayer10_size, buffer_params);
auto bayer8_buffer         = backend->CreateBuffer(bayer8_size,  buffer_params);
auto unbalanced_rgb_buffer = backend->CreateBuffer(rgb_size,     buffer_params);
auto balanced_rgb_buffer   = backend->CreateBuffer(rgb_size,     buffer_params);
auto i420_buffer           = backend->CreateBuffer(i420_size,    buffer_params);

Parameter objects

Parameter objects are created directly and not through a factory method. There are several different parameter objects used in different methods. The general list of parameter objects is as follows:

  • ColorSpaceParams - Used to indicate whether to apply an RGB to I420 conversion or an I420 to RGB conversion during a ColorSpaceConverter application.
  • CudaBufferParams - Used to indicate buffer CUDA memory type while creating a Buffer using the CUDA backend. The memory type can be Host, Device, Unified or External.
  • DebayerParams - Used to indicate the input Bayer layout during a Debayer application. The Bayer layout can be RGGB, BGGR, BRGB, or BGRB.
  • ShiftParams - Used to indicate the shift value during a Shift application. The shift value refers to how many bits to right-shift each input bayer pixel before converting to BAYER8.

This example creates a CudaBufferParams object and sets its CUDA memory type to external:

auto buffer_params = std::make_shared<CudaBufferParams>();
buffer_params->type = CudaType::kExternal;

Applying the algorithms

Each algorithm has an apply method that expects an input buffer, output buffer and parameter object.

shift->Apply(bayer10_buffer, bayer8_buffer, shift_params);
debayer->Apply(bayer8_buffer, unbalanced_rgb_buffer, debayer_params);
white_balancer->Apply(unbalanced_rgb_buffer, balanced_rgb_buffer, white_balancer_params);
color_space_converter->Apply(balanced_rgb_buffer, i420_buffer, color_space_converter_params);

More information

You can find more examples in our User Manual.



Previous: User Manual Index Next: Examples/GStreamer usage