16 #ifndef NVX_OPENCV_INTEROP_HPP
17 #define NVX_OPENCV_INTEROP_HPP
20 # error nvx_opencv_interop.hpp header must be compiled as C++
26 #include <opencv2/core/core.hpp>
27 #include <opencv2/core/gpumat.hpp>
66 CV_Error(CV_StsUnsupportedFormat,
"Unsupported format");
101 CV_Error(CV_StsUnsupportedFormat,
"Unsupported format");
146 return plane_index == 0 ? CV_8UC1 : CV_8UC2;
148 CV_Error(CV_StsUnsupportedFormat,
"Unsupported format");
185 CV_Error(CV_StsUnsupportedFormat,
"Unsupported format");
199 vx_size rows_num = 0, cols_num = 0;
207 CV_Assert(rows_num <= static_cast<vx_size>(std::numeric_limits<int>::max()));
211 CV_Assert(cols_num <= static_cast<vx_size>(std::numeric_limits<int>::max()));
214 CV_Assert(dst_mat.isContinuous());
230 vx_size dst_rows_num = 0, dst_cols_num = 0;
242 CV_Assert(src_mat.isContinuous());
243 CV_Assert(static_cast<vx_size>(src_mat.cols) == dst_cols_num && static_cast<vx_size>(src_mat.rows) == dst_rows_num);
262 src_mat.cols, src_mat.rows);
288 addrs[0].
dim_x = mat.cols;
289 addrs[0].dim_y = mat.rows;
290 addrs[0].stride_x =
static_cast<vx_int32>(mat.elemSize());
291 addrs[0].stride_y =
static_cast<vx_int32>(mat.step);
293 void *ptrs[1] = {
const_cast<uchar *
>(mat.ptr()) };
319 addrs[0].
dim_x = mat.cols;
320 addrs[0].dim_y = mat.rows;
321 addrs[0].stride_x =
static_cast<vx_int32>(mat.elemSize());
322 addrs[0].stride_y =
static_cast<vx_int32>(mat.step);
324 void *ptrs[1] = {
const_cast<uchar *
>(mat.ptr()) };
360 image_(image), plane_index_(plane_index), memory_type_(memory_type), ptr_(NULL)
368 rect_.
end_x = rect->end_x;
369 rect_.
end_y = rect->end_y;
397 cv_mat_ = cv::Mat(rows, cols, type, ptr_, step);
401 cv_gpumat_ = cv::gpu::GpuMat(rows, cols, type, ptr_, step);
420 CV_Assert(!cv_mat_.empty());
431 CV_Assert(!cv_gpumat_.empty());
445 cv::gpu::GpuMat cv_gpumat_;
struct _vx_image * vx_image
An opaque reference to an image.
VXImageToCVMatMapper(vx_image image, vx_uint32 plane_index=0, const vx_rectangle_t *rect=NULL, vx_enum usage=VX_READ_AND_WRITE, vx_enum memory_type=VX_IMPORT_TYPE_HOST)
Maps input OpenVX Image into OpenCV Mat or GpuMat without memory copy.
vx_status VX_API_CALL vxQueryImage(vx_image image, vx_enum attribute, void *ptr, vx_size size)
Retrieves various attributes of an image.
vx_status VX_API_CALL vxWriteMatrix(vx_matrix mat, const void *array)
Sets the matrix data (copy)
int convertVXMatrixTypeToCVMatType(vx_enum matrix_type)
Converts from OpenVX Matrix' type to OpenCV Mat's type.
vx_uint32 scale_y
Scale of Y dimension. For sub-sampled planes this is the scaling factor of the dimension of the plane...
vx_status nvxUnmapImagePatch(vx_image image, const vx_rectangle_t *rect, vx_uint32 plane_index, void *ptr, vx_enum memory_type)
Unmaps a mapped patch (subset) of an image.
size_t vx_size
A wrapper of size_t to keep the naming convention uniform.
vx_df_image convertCVMatTypeToVXImageFormat(int mat_type)
Converts from OpenCV Mat's type to OpenVX Image's format.
A 2-lane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling. This uses the BT709 full r...
int32_t vx_enum
Sets the standard enumeration type size to be a fixed quantity.
vx_status VX_API_CALL vxQueryMatrix(vx_matrix mat, vx_enum attribute, void *ptr, vx_size size)
Queries an attribute on the matrix object.
int32_t vx_int32
A 32-bit signed value.
NVIDIA VisionWorks Framework and Primitives API.
vx_image VX_API_CALL vxCreateImageFromHandle(vx_context context, vx_df_image color, vx_imagepatch_addressing_t addrs[], void *ptrs[], vx_enum import_type)
Creates a reference to an image object that was externally allocated.
A single plane of unsigned 32-bit data. The range of data is not specified, as it may be extracted fr...
A single plane of unsigned 8-bit data. The range of data is not specified, as it may be extracted fro...
vx_status nvxMapImagePatch(vx_image image, const vx_rectangle_t *rect, vx_uint32 plane_index, vx_imagepatch_addressing_t *addr, void **ptr, vx_enum usage, vx_enum memory_type, vx_uint32 flags)
Maps a rectangular patch (subset) of an image from a single plane.
A single plane of 48 bit pixels as 3 interleaved 16 bit signed integers of R then G then B data...
vx_status VX_API_CALL vxReadMatrix(vx_matrix mat, void *array)
Gets the matrix data (copy).
vx_enum vx_status
A formal status type with known fixed size.
vx_image createVXImageFromCVMat(vx_context context, const cv::Mat &mat)
Creates OpenVX Image from OpenCV Mat without data copy.
struct _vx_context * vx_context
An opaque reference to the implementation context.
vx_enum convertCVMatTypeToVXMatrixType(int mat_type)
Converts from OpenCV Mat's type to OpenVX Matrix' type.
~VXImageToCVMatMapper()
Unmaps a mapped region of an OpenVX Image.
#define NVX_MAP_NO_PIXEL_GAPS
Maps into a buffer without gaps between pixels in a row.
vx_uint32 start_x
The Start X coordinate.
struct _vx_reference * vx_reference
A generic opaque reference to any object within OpenVX.
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes. This uses the BT709 full range by defau...
Queries an image for its width. Use a vx_uint32 parameter.
void copyVXMatrixToCVMat(vx_matrix src_mat, cv::Mat &dst_mat)
Copies data from OpenVX Matrix to OpenCV Mat.
uint32_t vx_df_image
Used to hold a VX_DF_IMAGE code to describe the pixel format and color space.
A single plane of 24-bit pixel as 3 interleaved 8-bit units of R then G then B data. This uses the BT709 full range by default.
A virtual image of no defined type.
vx_uint32 dim_y
Height of patch in Y dimension in pixels.
void copyCVMatToVXMatrix(const cv::Mat &src_mat, vx_matrix dst_mat)
Copies data from OpenCV Mat to OpenVX Matrix.
The addressing image patch structure is used by the Host only to address pixels in an image patch...
A single plane of 32-bit pixel as 4 interleaved 8-bit units of R then G then B data, then a don't care byte. This uses the BT709 full range by default.
The memory shall be treated by the system as if it were readable and writeable.
The M dimension of the matrix. Use a vx_size parameter.
Queries an image for its format. Use a vx_df_image parameter.
The default memory type to import from the Host.
Queries an image for its height. Use a vx_uint32 parameter.
Utility class to map OpenVX Image into OpenCV Mat or GpuMat.
vx_uint32 start_y
The Start Y coordinate.
A single plane of vx_int16[2] data (eg.
vx_uint32 dim_x
Width of patch in X dimension in pixels.
The CUDA import memory type.
vx_matrix cloneCVMatToVXMatrix(vx_context context, const cv::Mat &src_mat)
Creates OpenVX Matrix object and copies data from OpenCV Mat.
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 bytes. This uses the BT709 full range by defau...
The rectangle data structure that is shared with the users.
vx_int32 stride_y
Stride in Y dimension in bytes.
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes. This uses the BT709 full range by default...
vx_uint32 end_x
The End X coordinate.
The N dimension of the matrix. Use a vx_size parameter.
A single plane of vx_float32 data.
vx_image createVXImageFromCVGpuMat(vx_context context, const cv::gpu::GpuMat &mat)
Creates OpenVX Image from OpenCV GpuMat without data copy.
cv::Mat getMat()
Gets mapped OpenCV Mat.
A single plane of signed 16-bit data. The range of data is not specified, as it may be extracted from...
uint32_t vx_uint32
A 32-bit unsigned value.
A 2-plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling. This uses the BT709 full ...
The value type of the matrix. Use a vx_enum parameter.
cv::gpu::GpuMat getGpuMat()
Gets mapped OpenCV GpuMat.
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes. This uses the BT709 full range by default...
A single plane of vx_float32[2] data (eg.
vx_uint32 end_y
The End Y coordinate.
struct _vx_matrix * vx_matrix
The Matrix Object. An MxN matrix of some unit type.
int convertVXImageFormatToCVMatType(vx_df_image format, vx_uint32 plane_index=0)
Converts from OpenVX Image's format to OpenCV Mat's type.
A single plane of unsigned 16-bit data. The range of data is not specified, as it may be extracted fr...
A single plane of unsigned 32-bit data. The range of data is not specified, as it may be extracted fr...
vx_uint32 scale_x
Scale of X dimension. For sub-sampled planes this is the scaling factor of the dimension of the plane...
vx_status VX_API_CALL vxGetStatus(vx_reference reference)
Provides a generic API to return status values from Object constructors if they fail.
vx_matrix VX_API_CALL vxCreateMatrix(vx_context c, vx_enum data_type, vx_size columns, vx_size rows)
Creates a reference to a matrix object.