Difference between revisions of "GstCUDA - Example - opencvfilter"

From RidgeRun Developer Connection
Jump to: navigation, search
(Add custom kernel properties and examples.)
Line 36: Line 36:
  
 
* '''dx'''<br/>
 
* '''dx'''<br/>
Derivative order in respect of X.<br/>
+
Derivative order in respect of X (for deriv, sobel and scharr).<br/>
 
Type: Integer<br/>
 
Type: Integer<br/>
 
Range: 0 - 2<br/>
 
Range: 0 - 2<br/>
Line 43: Line 43:
  
 
* '''dy'''<br/>
 
* '''dy'''<br/>
Derivative order in respect of Y.<br/>
+
Derivative order in respect of Y (for deriv, sobel and scharr).<br/>
 
Type: Integer<br/>
 
Type: Integer<br/>
 
Range: 0 - 2<br/>
 
Range: 0 - 2<br/>
Line 50: Line 50:
  
 
* '''scale'''<br/>
 
* '''scale'''<br/>
Optional scale factor for the computed values.<br/>
+
Optional scale factor for the computed values (for deriv, laplacian, sobel and scharr).<br/>
 
Type: Integer<br/>
 
Type: Integer<br/>
 
Range: 1 - 2147483647<br/>
 
Range: 1 - 2147483647<br/>
Line 57: Line 57:
  
 
* '''iterations'''<br/>
 
* '''iterations'''<br/>
Number of times for the morphological operations to be applied.<br/>
+
Number of times for the morphological operations to be applied (for morphology).<br/>
 
Type: Integer<br/>
 
Type: Integer<br/>
 
Range: 1 - 2147483647<br/>
 
Range: 1 - 2147483647<br/>
Line 64: Line 64:
  
 
* '''morph-op'''<br/>
 
* '''morph-op'''<br/>
Type of morphological operation. 0: Erode, 1: Dilate, 2: Open, 3: Close.<br/>
+
Type of morphological operation (for morphology). Available options:<br/>
Type: Integer<br/>
+
::'''erode''':  Normalized box filter
Range: 0 - 3<br/>
+
::'''dilate''': Maximum filter
 +
::'''open''': Minimum filter
 +
::'''close''': Vertical 1D box filter
 +
Flags: readable, writable<br/>
 +
Default: "erode"
 +
* '''kernel'''<br/>
 +
-2D matrix of NxM to use as kernel (for linear and morphology filters).<br/>
 +
-2D matrix of 1xM to use as a row kernel (for separable filter).<br/>
 +
Type: GstValueArray of GValues of type GstValueArray<br/>
 
Flags: readable, writable<br/>
 
Flags: readable, writable<br/>
Default: 0
+
Default: <<1.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,1.0>>
 +
 
 +
== Examples ==
 +
 
 +
The following examples pipe will help you apply different types of filters to the input video stream from your camera. These pipes were tested on both, the Nvidia Jetson TX1 and TX2.
  
== Example ==
+
=== Border Detection ===
The following example pipe will help you apply a sobel edge detector filter to the input video stream from your camera. This pipe was tested on both, the Nvidia Jetson TX1 and TX2.
 
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=sobel dx=0 dy=1 size=1 ! queue ! nvvidconv ! autovideosink
 
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=sobel dx=0 dy=1 size=1 ! queue ! nvvidconv ! autovideosink
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Linear Filter with Custom Kernel ===
 +
 +
<syntaxhighlight lang="bash">
 +
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=linear kernel="<<0.0,0.0, 0.0>,<0.0,0.5,0.0>,<0.0,0.0,0.0>>" ! queue ! nvvidconv ! autovideosink
 +
</syntaxhighlight>
 +
 +
=== Separable Filter with Custom Row and Column Kernels ===
 +
 +
<syntaxhighlight lang="bash">
 +
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=separable kernel="<<0.0,0.5,0.0>>" kernel2="<<0.2,0.2,0.7,0.5>>" ! queue ! nvvidconv ! autovideosink
 +
</syntaxhighlight>
 +
 +
 +
  
 
{{GstCUDA/Foot|previous=Example - opencvwarp|next=Performance Profiling}}
 
{{GstCUDA/Foot|previous=Example - opencvwarp|next=Performance Profiling}}

Revision as of 12:36, 17 September 2020


Previous: Example - opencvwarp Index Next: Performance Profiling


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



Introduction

The opencvfilter element exposes a series of image filters from the popular computer vision framework OpenCV. The following figure shows some of the available filters applied to the same image.

Figure 1. Example of opencv available filters.

Element properties

  • size

The size of the filter. Depending on the filter, it could either be the kernel size or the aperture size. Must be odd.
Type: Integer
Range: 1 - 2147483647
Flags: readable, writable
Default: 3

  • filter

Type of the filter to create. Available options:

box: Normalized box filter
box-max: Maximum filter
box-min: Minimum filter
column-sum: Vertical 1D box filter
deriv: General deriv filter
gaussian: Gaussian filter
laplacian: Laplacian filter
linear: General linear filter
morphology: Morphological filter
row-sum: Horizontal 1D box filter
scharr: Scharr filter
separable: Separable linear filter
sobel: Sobel filter

Flags: readable, writable
Default: "gaussian"

  • dx

Derivative order in respect of X (for deriv, sobel and scharr).
Type: Integer
Range: 0 - 2
Flags: readable, writable
Default: 0

  • dy

Derivative order in respect of Y (for deriv, sobel and scharr).
Type: Integer
Range: 0 - 2
Flags: readable, writable
Default: 0

  • scale

Optional scale factor for the computed values (for deriv, laplacian, sobel and scharr).
Type: Integer
Range: 1 - 2147483647
Flags: readable, writable
Default: 1

  • iterations

Number of times for the morphological operations to be applied (for morphology).
Type: Integer
Range: 1 - 2147483647
Flags: readable, writable
Default: 1

  • morph-op

Type of morphological operation (for morphology). Available options:

erode: Normalized box filter
dilate: Maximum filter
open: Minimum filter
close: Vertical 1D box filter

Flags: readable, writable
Default: "erode"

  • kernel

-2D matrix of NxM to use as kernel (for linear and morphology filters).
-2D matrix of 1xM to use as a row kernel (for separable filter).
Type: GstValueArray of GValues of type GstValueArray
Flags: readable, writable
Default: <<1.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,1.0>>

Examples

The following examples pipe will help you apply different types of filters to the input video stream from your camera. These pipes were tested on both, the Nvidia Jetson TX1 and TX2.

Border Detection

gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=sobel dx=0 dy=1 size=1 ! queue ! nvvidconv ! autovideosink

Linear Filter with Custom Kernel

gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=linear kernel="<<0.0,0.0, 0.0>,<0.0,0.5,0.0>,<0.0,0.0,0.0>>" ! queue ! nvvidconv ! autovideosink

Separable Filter with Custom Row and Column Kernels

gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=separable kernel="<<0.0,0.5,0.0>>" kernel2="<<0.2,0.2,0.7,0.5>>" ! queue ! nvvidconv ! autovideosink




Previous: Example - opencvwarp Index Next: Performance Profiling