VPI - Vision Programming Interface

1.0 Release

OpenCV Interoperability

Interoperability with OpenCV library. More...

Functions

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. More...
 
VPIStatus vpiImageCreateOpenCVMatWrapper (const cv::Mat &mat, uint32_t flags, VPIImage *img)
 Wraps a cv::Mat in an VPIImage and infers the image format from its type. More...
 
VPIStatus vpiImageSetWrappedOpenCVMat (VPIImage img, const cv::Mat &mat)
 Redefines the wrapped cv::Mat of an existing VPIImage wrapper. More...
 
VPIStatus vpiImageCreateOpenCVMatPlanesWrapper (const std::vector< cv::Mat > &matPlanes, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
 Wraps a vector of cv::Mat in a VPIImage, each cv::Mat representing one image plane. More...
 
VPIStatus vpiImageSetWrappedOpenCVMatPlanes (VPIImage img, const std::vector< cv::Mat > &matPlanes)
 Replaces the wrapped cv::Mat planes with new ones. More...
 
VPIStatus vpiImageDataExportOpenCVMat (const VPIImageData &imgData, cv::Mat *mat)
 Fills an existing cv::Mat with data from VPIImageData coming from a locked VPIImage. More...
 
VPIStatus vpiImageDataExportOpenCVMatPlanes (const VPIImageData &imgData, std::vector< cv::Mat > *matPlanes)
 Fills a vector of cv::Mat with all planes from VPIImageData. More...
 

Detailed Description

Interoperability with OpenCV library.

VPI allows easy interoperability with OpenCV. This makes it easy to wrap existing cv::Mat object into VPIImage to be used in VPI pipelines.

It's also possible to create a cv::Mat out of a VPIImageData. EGL is our main vehicle for interoperability with multimedia, camera and graphics APIs.

Function Documentation

◆ vpiImageCreateOpenCVMatPlanesWrapper()

VPIStatus vpiImageCreateOpenCVMatPlanesWrapper ( const std::vector< cv::Mat > &  matPlanes,
VPIImageFormat  fmt,
uint32_t  flags,
VPIImage img 
)
inline

#include <vpi/OpenCVInterop.hpp>

Wraps a vector of cv::Mat in a VPIImage, each cv::Mat representing one image plane.

The wrapped cv::Mats must not be destroyed while there's a VPIImage still wrapping it. The std::vector object itself isn't used so it can be destroyed, or even be temporary. Failure to keep cv::Mats allocated leads to undefined behavior.

Parameters
[in]matPlanesVector of cv::Mat, each one representing one image plane.
[in]fmtThe image format associated with matPlanes. An error is returned if this format isn't consistent the vector size and the contained cv::Mat's dimensions and type.
[in]flagsImage flags. Here it can be specified in what backends the image can be used by or-ing together VPIBackend flags. Set flags to 0 to enable it in all backends supported by the active VPI context.
[out]imgPointer to memory that will receive the created image handle.
Returns
an error code on failure else VPI_SUCCESS

Definition at line 201 of file OpenCVInterop.hpp.

+ Here is the call graph for this function:

◆ vpiImageCreateOpenCVMatWrapper() [1/2]

VPIStatus vpiImageCreateOpenCVMatWrapper ( const cv::Mat &  mat,
uint32_t  flags,
VPIImage img 
)
inline

#include <vpi/OpenCVInterop.hpp>

Wraps a cv::Mat in an VPIImage and infers the image format from its type.

The rules to infer the image type are:

  • unsigned and float 3-channel images are taken to be BGR
  • unsigned and float 4-channel images are taken to be BGRA
  • other types are mapped to non-color vpi image formats with the same pixel layout.

The cv::Mat must not be destroyed while there's a VPIImage still wrapping it. Failure to do so leads to undefined behavior.

Parameters
[in]matThe OpenCV matrix to be wrapped.
[in]flagsImage flags. Here it can be specified in what backends the image can be used by or-ing together VPIBackend flags. Set flags to 0 to enable it in all backends supported by the active VPI context.
[out]imgPointer to memory that will receive the created image handle.
Returns
an error code on failure else VPI_SUCCESS

Definition at line 133 of file OpenCVInterop.hpp.

+ Here is the call graph for this function:

◆ vpiImageCreateOpenCVMatWrapper() [2/2]

VPIStatus vpiImageCreateOpenCVMatWrapper ( const cv::Mat &  mat,
VPIImageFormat  fmt,
uint32_t  flags,
VPIImage img 
)
inline

#include <vpi/OpenCVInterop.hpp>

Wraps a cv::Mat in an VPIImage with the given image format.

It also wraps YUV images in 4:2:2 (packed and semi-planar) and 4:2:0 (semi-planar) formats that are understood by cv::cvtColor.

The cv::Mat must not be destroyed while there's a VPIImage still wrapping it. Failure to do so leads to undefined behavior.

Parameters
[in]matThe OpenCV matrix to be wrapped.
[in]fmtThe image format associated with fmt. An error is returned if this format isn't consistent with mat dimensions and type.
[in]flagsImage flags. Here it can be specified in what backends the image can be used by or-ing together VPIBackend flags. Set flags to 0 to enable it in all backends supported by the active VPI context.
[out]imgPointer to memory that will receive the created image handle.
Returns
an error code on failure else VPI_SUCCESS

Definition at line 101 of file OpenCVInterop.hpp.

+ Here is the call graph for this function:

◆ vpiImageDataExportOpenCVMat()

VPIStatus vpiImageDataExportOpenCVMat ( const VPIImageData imgData,
cv::Mat *  mat 
)
inline

#include <vpi/OpenCVInterop.hpp>

Fills an existing cv::Mat with data from VPIImageData coming from a locked VPIImage.

No image contents will be copied, they're just referenced by cv::Mat. The result can be used in OpenCV operations.

If imgData has 2 or 3 planes that are contiguous in memory and represent some multi-planar formats as understood by cv::cvtColor such as NV12 or YUV422, the resulting mat will be filled so that cv::cvtColor understand it as having these types. In other works, they can be used with cv::COLOR_YUV2RGB_NV12 or COLOR_YUV2RGB_UYVY.

Parameters
[in]imgDataReference to VPIImageData returned by vpiImageLock.
[in]matcv::Mat that wil refer to imgData contents.
Returns
an error code on failure else VPI_SUCCESS.

Definition at line 269 of file OpenCVInterop.hpp.

◆ vpiImageDataExportOpenCVMatPlanes()

VPIStatus vpiImageDataExportOpenCVMatPlanes ( const VPIImageData imgData,
std::vector< cv::Mat > *  matPlanes 
)
inline

#include <vpi/OpenCVInterop.hpp>

Fills a vector of cv::Mat with all planes from VPIImageData.

No image contents will be copied, they're just referenced by cv::Mat. The result can be used in OpenCV operations.

Parameters
[in]imgDataReference to VPIImageData returned by vpiImageLock.
[in]matPlanesVector of cv::Mat, each one wrapping one image plane in imgData.
Returns
an error code on failure else VPI_SUCCESS.

Definition at line 290 of file OpenCVInterop.hpp.

◆ vpiImageSetWrappedOpenCVMat()

VPIStatus vpiImageSetWrappedOpenCVMat ( VPIImage  img,
const cv::Mat &  mat 
)
inline

#include <vpi/OpenCVInterop.hpp>

Redefines the wrapped cv::Mat of an existing VPIImage wrapper.

The new cv::Mat must have the same characteristics (type and dimensions) of the existing cv::Mat being wrapped.

The VPIImage must have been created by vpiImageCreateOpenCVMatWrapper.

This operation is efficient and does not allocate memory. The wrapped memory will be accessible to the same backends specified during wrapper creation.

The wrapped cv::Mat must be valid while it's still being wrapped.

Parameters
[in]imgHandle to an image created by vpiImageCreateOpenCVMatWrapper .
[in]matcv::Mat object to be wrapped.
Returns
an error code on failure else VPI_SUCCESS.

Definition at line 163 of file OpenCVInterop.hpp.

+ Here is the call graph for this function:

◆ vpiImageSetWrappedOpenCVMatPlanes()

VPIStatus vpiImageSetWrappedOpenCVMatPlanes ( VPIImage  img,
const std::vector< cv::Mat > &  matPlanes 
)
inline

#include <vpi/OpenCVInterop.hpp>

Replaces the wrapped cv::Mat planes with new ones.

The new cv::Mat vector must have the same size, and contained cv::Mats must have the same characteristics (type and dimensions) of the existing cv::Mats being wrapped.

The VPIImage must have been created by vpiImageCreateOpenCVMatPlanesWrapper.

This operation is efficient and does not allocate memory. The wrapped memory will be accessible to the same backends specified during wrapper creation.

The wrapped cv::Mats must be valid while it's still being wrapped. The std::vector object itself can be destroyed, or even be temporary.

Parameters
[in]imgHandle to an image created by vpiImageCreateOpenCVMatPlanesWrapper .
[in]matPlanesVector of cv::Mat, each one representing one image plane.
Returns
an error code on failure else VPI_SUCCESS.

Definition at line 234 of file OpenCVInterop.hpp.

+ Here is the call graph for this function: