NVIDIA Vision Programming Interface (VPI) Demo
Contents
General Description
NVIDIA® Vision Programming Interface (VPI) is a library that abstracts heterogeneous computing on NVIDIA embedded devices. It aims to provide a common API to use different hardware modules for the acceleration of computer vision applications. It has the following features:
- Support for different processing backends [1] (CPU, GPU (CUDA), PVA [2])
- It allows a combination of different backends in the same processing pipeline. For example, one stage can be executed in the GPU, while the PVA would be executing another task within the same algorithm.
- Zero copy, shared memory mapping interface to manage data between the different backends.
- The API is designed to minimize memory allocations typically required just at the initialization stage of many computer vision algorithms. Many computer vision applications can be generalized as 3 stages: initialization, main loop and clean up, so the API facilitates building applications in this scheme.
- OpenCV and EGL Interoperability.
- Synchronization mechanisms that are agnostic of the backend being used. No matter the backend you use the same API.
Installation
The VPI (v0.1) was released with JetPack 4.3. It can be installed using the sdkmanager.
VPI installation path: /opt/nvidia/vpi/vpi-0.1
Architecture
VPI is written in C/C++. At it is shown in the figure below, this library provides a unified API (data structures, events, synchronization) for handling processing loads on different hardware accelerators.
Modules
- Core: Array, Context, Event, Image, Pyramid, Stream
- BilateralFilter
- BoxFilter
- GaussianFilter
- HarrisCornersDetector
- Convolve2D
- Resample
- KLTBoundingBoxTracker
- SeparableConvolve2D
- Stereo Disparity
- EGL Interoperability
You can find the full documentation of the API here: https://docs.nvidia.com/vpi/usergroup0.html
Samples
There are several samples starting at release 0.1. Samples are installed at /opt/nvidia/vpi/vpi-0.1. All samples are provided as simple CMake projects. Below are some instructions to build and test the samples.
- First, make sure to have all building tools required:
sudo apt-get install g++ cmake libopencv-dev
The following samples were tested in Jetson AGX Xavier
2D Image Convolution
This sample implements an image convolver with a simple edge detector kernel.
- To build one sample just follows these commands:
cd samples/01-convolve_2d cmake . make
- Usage
./vpi_sample_01_convolve_2d <backend> <input image>
The <backend> argument can be cpu, cuda or pva.
The <input image> argument is the path to a png or jpeg image.
The result is an image with the filename edges_<backend>.png depending on the backend you set.
Stereo Disparity Estimator
This sample implements the disparity estimation from two stereo images (left and right).
- To build one sample just follows these commands:
cd samples/02-stereo_disparity cmake . make
- Usage
./vpi_sample_02_stereo_disparity <backend> <input image> <input image>
The <backend> argument can be cpu, cuda or pva.
This application requires two images for the stereo pair estimation
The result is an image with the filename disparity_<backend>.png depending on the backend you set.
Harris Keypoint Extrator
This sample implements a detector of Harris corners.
- To build one sample just follows these commands:
cd samples/03-harris_keypoints cmake . make
- Usage
./vpi_sample_03_harris_keypoints <backend> <input image>
The <input image> argument is the path to a png or jpeg image.
The <backend> argument can be cpu, cuda or pva. Note: This sample does not support the pva backend.
The result is an image with the filename harris_keypoints_<backend>.png depending on the backend you set.
Image Resampling
This sample implements an image resampler (low-pass filter + downscaling).
cd samples/04-resample cmake . make
- Usage
./vpi_sample_04_resample <backend> <input image>
The <input image> argument is the path to a png or jpeg image.
The <backend> argument can be cpu, cuda or pva. Note: This sample does not support the pva backend.
The result is an image with the filename resampled_<backend>.png depending on the backend you set.
Measure Execution Time
cd samples/05-timing cmake . make
- Usage
./vpi_sample_05_timing <backend>
The <backend> argument can be cpu, cuda or pva.
The result is an image resampled (though it is not actually wrote into the disk) and some printed messages with measure of elapsed time between events.
- Results
nvidia@nvidia:~/vpi-0.1-samples/samples/05-timing$ ./vpi_sample_05_timing cpu Input size: 1920 x 1080 NVMEDIA_ARRAY: 53, Version 2.1 NVMEDIA_VPI : 156, Version 2.3 Blurring elapsed time: 270.452057 ms Gaussian pyramid elapsed time: 55.426395 ms Total elapsed time: 325.878479 ms nvidia@nvidia:~/vpi-0.1-samples/samples/05-timing$ ./vpi_sample_05_timing cuda Input size: 1920 x 1080 NVMEDIA_ARRAY: 53, Version 2.1 NVMEDIA_VPI : 156, Version 2.3 Blurring elapsed time: 8.427521 ms Gaussian pyramid elapsed time: 5.799936 ms Total elapsed time: 14.227456 ms nvidia@nvidia:~/vpi-0.1-samples/samples/05-timing$ ./vpi_sample_05_timing pva Input size: 1920 x 1080 NVMEDIA_ARRAY: 53, Version 2.1 NVMEDIA_VPI : 156, Version 2.3 Blurring elapsed time: 53.625671 ms Gaussian pyramid elapsed time: 17.314356 ms Total elapsed time: 70.940025 ms
KLT Bounding Box Tracker
This sample implements a bounding box tracker using Kanade–Lucas–Tomasi feature tracker (KLT).
cd samples/06-klt_tracker cmake . make
- Usage
./vpi_sample_06_klt_tracker <backend> <input video> <input bboxes> <output frames>
The <input video> argument is the path to a video from which to extract the frames to be processed. The <backend> argument can be cpu, cuda or pva. The <input boxes> argument is a text file containing input bounding boxes. It must follow the structure: <frame> <bbox_x> <bbox_y> <bbox_width> <bbox_height> The <output frames> argument is the prefix for all output frames.
Image Filter (blur)
This sample implements a 2D box filter (mean filter) over an input image.
cd samples/tutorial_blur cmake . make
- Usage
./vpi_blur <image file name>
This sample uses only the CUDA backend.
The <image file name> argument is the path to a png or jpeg image.
The result is a blurred image saved in png format.
Demo
- The demo captures images from camera, and process the live streaming frame by frame. Processed frames are store as png files.
- Input frames are stored using H264 (GStreamer) in a mastroska container.
- The demo can be used in all backends (Jetson AGX Xavier)
- Usage:
./demo-gstreamer-vpi <backend>
Where <backend> argument can be: cpu, cuda or pva.
Demo repository: https://gitlab.com/RidgeRun/code-snippets/jetson/xavier/demo-gstreamer-vpi
Performance
The following table summarizes some throughput data obtained after running the demo app 10 times for 300 frames each in a Jetson AGX Xavier with default performance settings. CPU load measurements were obtained with tegrastats.
Backend | CPU load (%) | Frame rate (fps) | Elapsed Time (ms) |
---|---|---|---|
CPU | ~80% | 25.15 | 39.76 |
CUDA | ~70% | 325.39 | 3.07 |
PVA | ~66% | 129.95 | 7.70 |