|
|
VisionWorks Toolkit ReferenceApril 8, 2016 | 1.4 Release |
This section demonstrates how to convert between OpenCV and OpenVX data types.
To simplify interaction with OpenCV, VisionWorks provides auxiliary header nvx_opencv_interop.hpp, which contains utility function to convert between OpenCV and OpenVX data types.
OpenCV uses cv::Mat data type as the main data type for all operations. The cv::Mat object can be converted to vx_matrix and vx_image objects.
The following code example shows how to copy cv::Mat object into vx_matrix object. Since it is a copy, vx_matrix object is fully independent from the source cv::Mat object.
The following code example shows how to import cv::Mat object into vx_image object without memory copy. The vx_image object points to the same pixels as the cv::Mat. The code internally uses the vxCreateImageFromHandle function and has the same limitations (see Image Data Object Extensions):
cv::Mat object must not be released until the corresponding vx_image object is destroyed.cv::Mat object. It must use vxAccessImagePatch/vxCommitImagePatch functions.vx_image, the ownership of the memory is transferred back to the source cv::Mat and the cv::Mat contains up-to-date pixel data. cv::gpu::GpuMat can be imported as well with the same limitations:
vx_matrix and vx_image objects can be converted in cv::Mat object.
The following code example shows how to copy vx_matrix object into cv::Mat object. Since it is a copy, cv::Mat object is fully independent from the source vx_matrix object.
The following code example shows how to map vx_image object into cv::Mat object without memory copy. The cv::Mat object points to the same pixels as the vx_image object. The nvx_cv::VXImageToCVMatMapper class internally uses the nvxMapImagePatch method and has the same limitations:
vx_image object must not be destroyed until nvx_cv::VXImageToCVMatMapper destructor is called since the destructor unmaps the mapped patch. vx_image can be mapped to cv::gpu::GpuMat object as well: