The C API provides low level access to all VPI functionality. It gives the developer more control on resource management, pipeline construction leading to more efficient processing in time and memory consumption.
Create the cmake project to build the application as follows.
1 cmake_minimum_required(VERSION 3.5)
5 # This instructs cmake to look for the most recent
6 # vpi instance installed on the system.
7 find_package(vpi REQUIRED)
8 find_package(OpenCV REQUIRED)
10 # Creates the blur executable target
11 add_executable(vpi_blur main.cpp)
13 # It uses vpi and opencv. CMake will automatically
14 # set up the correct header and library directories,
15 # and make hello_work link to these libraries.
16 target_link_libraries(vpi_blur vpi opencv_core opencv_imgproc)
18 # OpenCV < 3 uses a different library for image i/o
19 if(OpenCV_VERSION VERSION_LESS 3)
20 target_link_libraries(vpi_blur opencv_highgui)
22 target_link_libraries(vpi_blur opencv_imgcodecs)
Note that cmake automatically sets up the VPI header and library paths for the executable. It is not necessary to manually define them.
30 #include <opencv2/core/version.hpp>
31 #include <opencv2/imgproc/imgproc.hpp>
32 #if CV_MAJOR_VERSION >= 3
33 # include <opencv2/imgcodecs.hpp>
35 # include <opencv2/highgui/highgui.hpp>
52 int main(
int argc,
char *argv[])
56 std::cerr <<
"Must pass an input image to be blurred" << std::endl;
63 cv::Mat cvImage = cv::imread(argv[1]);
64 if (cvImage.data == NULL)
66 std::cerr <<
"Can't open input image" << std::endl;
123 imwrite(
"tutorial_blurred.png", cvOut);
Declares functions that implement the Box Filter algorithm.
Functions and structures for dealing with VPI images.
Functions for handling OpenCV interoperability with VPI.
Declares functions dealing with VPI streams.
VPIStatus vpiSubmitBoxFilter(VPIStream stream, uint32_t backend, VPIImage input, VPIImage output, int32_t kernelSizeX, int32_t kernelSizeY, VPIBorderExtension border)
Runs a 2D box filter over an image.
VPIStatus vpiImageLock(VPIImage img, VPILockMode mode, VPIImageData *hostData)
Acquires the lock on an image object and returns a pointer to the image planes.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
Stores information about image characteristics and content.
VPIStatus vpiImageDataExportOpenCVMat(const VPIImageData &imgData, cv::Mat *mat)
Fills an existing cv::Mat with data from VPIImageData coming from a locked VPIImage.
VPIStatus vpiImageCreateOpenCVMatWrapper(const cv::Mat &mat, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Wraps a cv::Mat in an VPIImage with the given image format.
struct VPIStreamImpl * VPIStream
A handle to a stream.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
@ VPI_BACKEND_CUDA
CUDA backend.
@ VPI_BORDER_ZERO
All pixels outside the image are considered to be zero.
@ VPI_LOCK_READ
Lock memory only for reading.