• 04/03/2020
  • Public Content
Contents

Interoperability with OpenCV Transparent API

OpenCV 3.0 introduced new Transparent API that enables OpenCL*-based codepaths for OpenCV functions. The T-API is based on
cv::Umat
objects, which abstract data representation. Notice that all access to
cv::Umat
objects should be done via
cv::UMat
methods and not directly via data pointers.
To mix
cv::UMat
and
vx_image
objects you can use
vx_image->cv::Mat
mapping approach described above, followed by the OpenCV
copyTo
method to propagate data from the mapped
cv::Mat
and
cv::UMat
objects:
void callOpenCV_TAPI(vx_image input, vx_image output) { vx_uint32 width = 0, height = 0; vxQueryImage(input, VX_IMAGE_WIDTH, &width, sizeof(width)); vxQueryImage(input, VX_IMAGE_HEIGHT, &height, sizeof(height)); vx_rectangle_t rect = { 0u, 0u, width, height }; vx_imagepatch_addressing_t input_addr = {}; void *input_ptr = nullptr; vx_map_id map_id_in; vxMapImagePatch(input, &rect, 0, &map_id_in, &input_addr, &input_ptr, VX_READ_ONLY); vx_imagepatch_addressing_t output_addr = {}; void *output_ptr = nullptr; vx_map_id map_id_out; vxMapImagePatch(output, &rect, 0, & map_id_out , &output_addr, &output_ptr, VX_WRITE_ONLY); cv::Mat mat_input(input_addr.dim_y * VX_SCALE_UNITY / input_addr.scale_y, input_addr.dim_x * VX_SCALE_UNITY / input_addr.scale_x, CV_8UC1, input_ptr, input_addr.stride_y); cv::Mat mat_output( output_addr.dim_y * VX_SCALE_UNITY / output_addr.scale_y, output_addr.dim_x * VX_SCALE_UNITY / output_addr.scale_x, CV_8UC1, output_ptr, output_addr.stride_y); cv::UMat umat_input; mat_input.copyTo(umat_input); cv::UMat umat_tmp, umat_output; cv::GaussianBlur(umat_input, umat_tmp, cv::Size(5, 5), 1.5); cv::Canny(umat_tmp, umat_output, 50, 100); umat_output.copyTo(mat_output); vxUnmapImagePatch(input, map_id_in); }

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.