Difference between revisions of "GstCUDA - Example - opencvwarp"

From RidgeRun Developer Connection
Jump to: navigation, search
(Created page with "{{GstCUDA/Head|previous=Examples|next=Example - cudafilter: NVMM direct mapping|keywords=GstCUDA Examples,opencvwarp,opencvfilter, opencv examples}} This page introduces two...")
 
m
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{GstCUDA/Head|previous=Examples|next=Example - cudafilter: NVMM direct mapping|keywords=GstCUDA Examples,opencvwarp,opencvfilter, opencv examples}}
+
{{GstCUDA/Head|previous=Example: opencv|next=Example - opencvfilter|metakeywords=GstCUDA Examples, opencvwarp, opencvfilter, opencv examples}}
 
 
This page introduces two [https://developer.ridgerun.com/wiki/index.php?title=GstCUDA GstCUDA] example elements, which offer [https://opencv.org/ OpenCV] based image warping and filtering capabilities while being accelerated using the GPU for maximum performance.
 
  
 
__TOC__
 
__TOC__
  
 
== Introduction ==
 
== Introduction ==
GstCUDA offers two basic library examples, which combine the use of the widely known computer vision library OpenCV with the high performance inherent to CUDA based algorithms.  They come ready to work just out of the box, so they are perfect for training and taking the first steps into GstCUDA.
 
  
The idea is to give detailed examples on how to use the '''''cudafilter''''' element, and also to give some examples of written code of a functional (out of the box) CUDA algorithm library for the '''''cudafilter''''' element.
+
The opencvwarp element will modify an image given a 3x3 transformation matrix. If the demo property of the element is enabled, it will apply a transformation that involves a rotation of the image in a 3D space and then a projection back to the image plane like this:
 +
 
 +
[[File:Opencvwarp demo example.gif|500px|frame|center|Figure 1. Opencvwarp demo transformation]]
 +
 
 +
== Element properties ==
 +
 
 +
* '''demo'''<br/>
 +
Put the element in demo mode to showcase its capabilities. In this mode, the incoming image will be rotated in the 3D space and projected back to the image plane. Will override the transformation matrix.<br/>
 +
Type: Boolean<br/>
 +
Flags: readable, writable<br/>
 +
Default: false
  
The CUDA algorithm library examples are built automatically, and you can find them under the following paths:
+
* '''m00-m22'''<br/>
* '''''$GstCUDA_DIR/tests/examples/cudafilter_algorithms/memcpy/memcpy.so'''''
+
The 9 coefficients of the 3x3 perspective transformation matrix. This matrix may be changed dynamically to animate transformations.<br/>
* '''''$GstCUDA_DIR/tests/examples/cudafilter_algorithms/gray-scale-filter/gray-scale-filter.so'''''
+
Type: Double<br/>
* '''''$GstCUDA_DIR/tests/examples/cudafilter_algorithms/median-filter/median-filter.so'''''
+
Range: -1,797693e+308 -   1,797693e+308
 +
Flags: readable, writable<br/>
 +
Default: identity matrix
  
The '''''memcpy.so''''' CUDA algorithm library consists in a very basic algorithm that receives a full-color YUV I420 image and generate and exact copy of the incoming image. It is a basic image filter that copies the luminance and chrominance components of the incoming image. The image copy is executed on the GPU, so it is hardware accelerated, that assures an optimal performance. This basic algorithm is just for example and demonstration purposes, because it shows the capability of GstCUDA to execute an algorithm on the GPU that go through each pixel in the incoming image and copies it to the output image. This can be a high load task if we consider a 4K@60fps video stream, due to the high data transaction rate, but GstCUDA could handle it with no problem.  
+
== Examples ==
 +
The following two examples will provide an introduction to the element and its capabilities. Both examples were tested on '''Nvidia Jetson TX1''' and '''TX2''' connected to a display via HDMI and using a webcam as input video source.
  
The '''''gray-scale-filter.so''''' CUDA algorithm library consists in a very basic algorithm that receives a full-color YUV I420 image and convert it to a gray-scale YUV I420 image. It is a basic image filter that modifies the chrominance components of the image by assigning a fixed value that makes the image to look in gray-scale. All the processing of the image is done in the GPU.
+
=== Demo example ===
 +
This example is meant to show the element capabilities. The image will be rotated in three-dimensional space and projected back to the image plane.
  
The '''''median-filter.so''''' CUDA algorith is a basic implementation of a median filter that takes a full-color YUV I420 image and applies a median filter to the image. This allows to remove basic salt-and-pepper noise in an image. The filter process is done in the GPU.
+
By running the following pipeline:
 +
<syntaxhighlight lang="bash">
 +
gst-launch-1.0 v4l2src ! nvvidconv ! opencvwarp demo=true ! queue ! nvvidconv ! autovideosink
 +
</syntaxhighlight>
  
GstCUDA supports two modes of memory handling. NVMM direct mapping mode use the CUDA mapper and the element receives NVMM memory type buffers as input. Unified memory allocator mode avoids the use of NVMM memory buffers by providing a memory allocator that directly pass the buffer to the GPU. Both modes are supported for Jetpack 3.0, however NVMM direct mapping mode is not supported for Jetpack 3.1.
+
you should obtain the result shown in Figure 1.
  
Below you will find a set of test pipelines for both modes, with their respective performance stats for each CUDA algorithm library.
+
=== Custom example ===
 +
You can also define your own custom matrix, as shown below.
  
'''''Note:''''' To get the best performance on the Tegra platform, you must execute the jetson_clocks.sh script. This script tune-up the Tegra to high performance mode. All the reported performance stats came from tests done after ran the jetson_clocks.sh script.
+
<syntaxhighlight lang="bash">
Execute command: ''sudo ~/jetson_clocks.sh''
+
#!/bin/bash
  
== Examples Index ==
+
m00=0.7071068
<html>
+
m01=-0.7071068
  <div class="toc" style="font-size:80%;">
+
m02=0.0000000
    <ol>
+
m10=0.7071068
      <li> <a href=https://developer.ridgerun.com/wiki/index.php?title=GstCUDA_-_Example_-_cudafilter:_NVMM_direct_mapping>NVMM direct mapping mode</a></li>
+
m11=0.7071068
      <li> <a href=https://developer.ridgerun.com/wiki/index.php?title=GstCUDA_-_Example_-_cudafilter:_Unified_memory_allocator>Unified memory allocator mode</a></li>
+
m12=0.0000000
    </ol>
+
m20=0.0000000
  </div>
+
m21=0.0000000
</html>
+
m22=1.0000000
  
{{GstCUDA/Foot|previous=Examples|next=Example - cudafilter: NVMM direct mapping|keywords=GstCUDA Examples,cudafilter,cudafilter example}}
+
gst-launch-1.0 v4l2src device=/dev/video1 ! nvvidconv \
 +
! opencvwarp m00=$m00 m01=$m01 m02=$m02 m10=$m10 m11=$m11 m12=$m12 m20=$m20 m21=$m21 m22=$m22 \
 +
! queue ! nvvidconv ! autovideosink
 +
</syntaxhighlight>
 +
{{GstCUDA/Foot|previous=Example: opencv|next=Example - opencvfilter}}

Latest revision as of 09:32, 10 March 2023


Previous: Example: opencv Index Next: Example - opencvfilter


Nvidia-preferred-partner-badge-rgb-for-screen.png



Introduction

The opencvwarp element will modify an image given a 3x3 transformation matrix. If the demo property of the element is enabled, it will apply a transformation that involves a rotation of the image in a 3D space and then a projection back to the image plane like this:

Error creating thumbnail: Unable to save thumbnail to destination
Figure 1. Opencvwarp demo transformation

Element properties

  • demo

Put the element in demo mode to showcase its capabilities. In this mode, the incoming image will be rotated in the 3D space and projected back to the image plane. Will override the transformation matrix.
Type: Boolean
Flags: readable, writable
Default: false

  • m00-m22

The 9 coefficients of the 3x3 perspective transformation matrix. This matrix may be changed dynamically to animate transformations.
Type: Double
Range: -1,797693e+308 - 1,797693e+308 Flags: readable, writable
Default: identity matrix

Examples

The following two examples will provide an introduction to the element and its capabilities. Both examples were tested on Nvidia Jetson TX1 and TX2 connected to a display via HDMI and using a webcam as input video source.

Demo example

This example is meant to show the element capabilities. The image will be rotated in three-dimensional space and projected back to the image plane.

By running the following pipeline:

gst-launch-1.0 v4l2src ! nvvidconv ! opencvwarp demo=true ! queue ! nvvidconv ! autovideosink

you should obtain the result shown in Figure 1.

Custom example

You can also define your own custom matrix, as shown below.

#!/bin/bash

m00=0.7071068
m01=-0.7071068
m02=0.0000000
m10=0.7071068
m11=0.7071068
m12=0.0000000
m20=0.0000000
m21=0.0000000
m22=1.0000000

gst-launch-1.0 v4l2src device=/dev/video1 ! nvvidconv \
! opencvwarp m00=$m00 m01=$m01 m02=$m02 m10=$m10 m11=$m11 m12=$m12 m20=$m20 m21=$m21 m22=$m22 \
! queue ! nvvidconv ! autovideosink


Previous: Example: opencv Index Next: Example - opencvfilter