Difference between revisions of "GstCUDA - Example - opencvfilter"
(Replaced content with "{{GstCUDA/Head|previous=Examples|next=Example - cudafilter: NVMM direct mapping|keywords=GstCUDA Examples,opencvwarp,opencvfilter, opencv examples}} This page is under co...") (Tag: Replaced) |
m |
||
(17 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{GstCUDA/Head|previous= | + | {{GstCUDA/Head|previous=Example - opencvwarp|next=Performance Profiling|metakeywords=GstCUDA Examples, opencvwarp, opencvfilter, opencv examples}} |
− | |||
− | |||
__TOC__ | __TOC__ | ||
== Introduction == | == 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. | ||
+ | |||
+ | [[File:GstCuda opencvfilter example.png|800px|thumb|center|Figure 1. Example of opencv available filters.]] | ||
+ | |||
+ | == Element properties == | ||
+ | |||
+ | * '''size'''<br/> | ||
+ | The size of the filter. Depending on the filter, it could either be the kernel size or the aperture size. Must be odd.<br/> | ||
+ | Type: Integer<br/> | ||
+ | Range: 1 - 2147483647<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: 3 | ||
+ | |||
+ | * '''filter'''<br/> | ||
+ | Type of the filter to create. Available options: <br/> | ||
+ | ::'''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<br/> | ||
+ | Default: "gaussian" | ||
+ | |||
+ | * '''dx'''<br/> | ||
+ | Derivative order in respect of X (for deriv, sobel and scharr).<br/> | ||
+ | Type: Integer<br/> | ||
+ | Range: 0 - 2<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: 0 | ||
+ | |||
+ | * '''dy'''<br/> | ||
+ | Derivative order in respect of Y (for deriv, sobel and scharr).<br/> | ||
+ | Type: Integer<br/> | ||
+ | Range: 0 - 2<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: 0 | ||
+ | |||
+ | * '''scale'''<br/> | ||
+ | Optional scale factor for the computed values (for deriv, laplacian, sobel and scharr).<br/> | ||
+ | Type: Integer<br/> | ||
+ | Range: 1 - 2147483647<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: 1 | ||
+ | |||
+ | * '''iterations'''<br/> | ||
+ | Number of times for the morphological operations to be applied (for morphology).<br/> | ||
+ | Type: Integer<br/> | ||
+ | Range: 1 - 2147483647<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: 1 | ||
+ | |||
+ | * '''morph-op'''<br/> | ||
+ | Type of morphological operation (for morphology). Available options:<br/> | ||
+ | ::'''erode''': Normalized box filter | ||
+ | ::'''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/> | ||
+ | Default: <<0.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,0.0>> | ||
+ | * '''kernel2'''<br/> | ||
+ | -2D matrix of 1xM to use as a column kernel (for separable filter).<br/> | ||
+ | Type: GstValueArray of GValues of type GstValueArray<br/> | ||
+ | Flags: readable, writable<br/> | ||
+ | Default: <<0.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,0.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 === | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=sobel dx=0 dy=1 size=1 ! queue ! nvvidconv ! autovideosink | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Linear Filter with Custom Kernel === | ||
+ | |||
+ | For a Gaussian filter given by the following 2D kernel: | ||
+ | |||
+ | <center> | ||
+ | <math> | ||
+ | K = | ||
+ | \begin{bmatrix} | ||
+ | 0.0625 & 0.125 & 0.0625 \\ | ||
+ | 0.125 & 0.25 & 0.125 \\ | ||
+ | 0.0625 & 0.125 & 0.0625 \\ | ||
+ | \end{bmatrix} | ||
+ | </math> | ||
+ | </center> | ||
+ | |||
+ | You may use the following pipeline: | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=linear kernel="<<0.0625,0.125,0.0625>,<0.125,0.25,0.125>,<0.0625,0.125,0.0625>>" ! queue ! nvvidconv ! autovideosink | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Separable Filter with Custom Row and Column Kernels === | ||
+ | |||
+ | For a Gaussian filter given by the row kernel: | ||
+ | |||
+ | <center> | ||
+ | <math> | ||
+ | K_{row} = | ||
+ | \begin{bmatrix} | ||
+ | 0.25 & 0.5 & 0.25 \\ | ||
+ | \end{bmatrix} | ||
+ | </math> | ||
+ | </center> | ||
+ | |||
+ | and the column kernel: | ||
+ | |||
+ | <center> | ||
+ | <math> | ||
+ | K_{col} = | ||
+ | \begin{bmatrix} | ||
+ | 0.111 \\ | ||
+ | 0.388 \\ | ||
+ | 0.388 \\ | ||
+ | 0.111 \\ | ||
+ | \end{bmatrix} | ||
+ | </math> | ||
+ | </center> | ||
+ | |||
+ | You may use the following pipeline: | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=separable kernel="<<0.25,0.5,0.25>>" kernel2="<<0.111,0.388,0.388,0.111>>" ! queue ! nvvidconv ! autovideosink | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Performance Measurements== | ||
+ | |||
− | {{GstCUDA/Foot|previous | + | {{GstCUDA/Foot|previous=Example - opencvwarp|next=Performance Profiling}} |
Latest revision as of 02:51, 17 March 2023
Contents
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.
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: <<0.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,0.0>>
- kernel2
-2D matrix of 1xM to use as a column kernel (for separable filter).
Type: GstValueArray of GValues of type GstValueArray
Flags: readable, writable
Default: <<0.0,0.0,0.0>,<0.0,1.0,0.0>,<0.0,0.0,0.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
For a Gaussian filter given by the following 2D kernel:
[math]\displaystyle{ K = \begin{bmatrix} 0.0625 & 0.125 & 0.0625 \\ 0.125 & 0.25 & 0.125 \\ 0.0625 & 0.125 & 0.0625 \\ \end{bmatrix} }[/math]
You may use the following pipeline:
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=linear kernel="<<0.0625,0.125,0.0625>,<0.125,0.25,0.125>,<0.0625,0.125,0.0625>>" ! queue ! nvvidconv ! autovideosink
Separable Filter with Custom Row and Column Kernels
For a Gaussian filter given by the row kernel:
[math]\displaystyle{ K_{row} = \begin{bmatrix} 0.25 & 0.5 & 0.25 \\ \end{bmatrix} }[/math]
and the column kernel:
[math]\displaystyle{ K_{col} = \begin{bmatrix} 0.111 \\ 0.388 \\ 0.388 \\ 0.111 \\ \end{bmatrix} }[/math]
You may use the following pipeline:
gst-launch-1.0 v4l2src ! nvvidconv ! opencvfilter filter=separable kernel="<<0.25,0.5,0.25>>" kernel2="<<0.111,0.388,0.388,0.111>>" ! queue ! nvvidconv ! autovideosink
Performance Measurements