GstCUDA - Example - opencvfilter
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:
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:
and the column kernel:
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