As preprocessing for image processing, resizing (enlarging/reducing) and format conversion are common processes. Therefore, if these processes are implemented inefficiently, they will consume computational resources unexpectedly and throughput will not increase. For the fourth article in the series, let's consider how to implement resizing and format conversion with Jetson.
[Jetson video processing programming]
Episode 1 What you can do with JetPack and SDK provided by NVIDIA
Episode 2 Video input (CSI-connected Libargus-compliant camera)
Episode 3 Video input (USB-connected V4L2-compliant camera)
Episode 4 Resize and format conversion
Comparison of implementation methods
Both resizing and format conversion can be implemented in multiple ways. Below is a comparison of them.
APIs |
programming language |
Strong Points |
Cons/Challenges |
GStreamer |
C Python |
|
|
OpenCV |
C Python |
|
|
VPI |
C++ Python will also be supported |
|
|
Multimedia API | C++ |
|
|
NVIDIA Performance Primitives (NPPs) | C |
|
|
When using GStreamer
It can be implemented with the nvvidconv plugin. An example is shown below. This example can be run on the command line, but should be programmed using the GStreamer API (C or Python) when embedded in an application.
Note: The output format (YUYV) of the webcam used for testing (Logitech C270n HD webcam) does not support the input (sink) format to the nvvidconv plugin, so the videoconvert plugin (In this example, it is converted to NV12).
$ gst-launch-1.0 -e \ v4l2src device="/dev/video0" ! \ "video/x-raw, width=(int)640, height=(int)480" ! \ videoconvert ! \ "video/x-raw, format=(string)NV12" ! \ nvvidconv interpolation-method=Bilinear flip-method=horizontal-flip ! \ "video/x-raw(memory:NVMM), format=(string)RGBA, width=(int)1280, height=(int)960" ! \ nv3dsink
When using OpenCV
- Resize (CUDA version)
- Resize (CPU version)
- Format conversion (CUDA version)
- Format conversion (CPU version)
The OpenCV included in JetPack is built with CUDA disabled. If you want to use the CUDA version of the functions, you need to build and install with CUDA enabled.
Reference: JEP/script/install_opencv4.5.0_Jetson.sh
When using VPI
By using the Vision Programming Interface (VPI), processing with different backends (CPU / CUDA / PVA / VIC) can be described with the same API.
More information on resizing and format conversion can be found at Convert Image Format.
You can understand how to use the Image Resampling sample program. The method of executing this sample program is introduced below.
$ cp -r /opt/nvidia/vpi1/samples/04-rescale/ ./
$ cd 04-rescale/
$ mkdir build
$ cd build
$ cmake ..
$ ./vpi_sample_04_rescale cuda /opt/nvidia/vpi1/samples/assets/kodim08.png
When using Multimedia API
You can see how to use it in the 07_video_convert sample code. The sample program exists in the following path.
/usr/src/jetson_multimedia_api/samples/07_video_convert
When using NPP
NVIDIA Performance Primitives (NPP) enable very high throughput resizing and format conversion.
Next time, I will explain how to display images!
How was the fourth episode of the series "Jetson Video Processing Programming", introducing resizing and format conversion?
In the next episode 5, I will introduce how to display images.
If you have any questions, please feel free to contact us.
We offer selection and support for hardware NVIDIA GPU cards and GPU workstations, as well as facial recognition, route analysis, skeleton detection algorithms, and learning environment construction services. If you have any problems, please feel free to contact us.