简体   繁体   中英

VisionWorks create Mat vx_image from Mat

I am following the opencv_npp_interop example as reference to convert an OpenCv Mat to vx_image but the example only shows for greyscale image (single channel). So I have tried to modify it for 3-channel (RGB) Mat to vx_image (RGB).

vx_image createRGBImageFromRGBMat(vx_context& context, cv::Mat& mat)
{
    vx_imagepatch_addressing_t src_addr = {
        mat.cols, mat.rows, sizeof(vx_uint8)*3, mat.cols * sizeof(vx_uint8)*3, VX_SCALE_UNITY, VX_SCALE_UNITY, 1, 1 };
    void* src_ptr = mat.data;

    vx_image image = vxCreateImageFromHandle(context, VX_DF_IMAGE_RGB, &src_addr, &src_ptr, VX_IMPORT_TYPE_HOST);

    return image;
}

If I query number of planes attribute for the returned vx_image, I only shows 1 plane. Whereas I am assuming it should be 3-plane (RGB).

Secondly, if I now convert this returned supposedly RGB image to YUV and query for planes, I get 3 planes but when I extract separate channels, I am only able to extract "Y" channel, other two vxuChannelExtract calls result in a "-10 : invalid params".

So I am assuming the source of the problem is still the RGB conversion. What did I do wrong ?

As in documentation RGB format has only one plane

VX_DF_IMAGE_RGB - A single plane of 24-bit pixel as 3 interleaved 8-bit units of R then G then B data.

Maybe you specify wrong enum for YUV channels, I've succeeded with this:

vx_image image = createRGBImageFromRGBMat(context, mat);
vx_image yuv = vxCreateImage(context, mat.cols, mat.rows, VX_DF_IMAGE_YUV4);
vxuColorConvert(context, image, yuv);
vx_image y = vxCreateImage(context, mat.cols, mat.rows, VX_DF_IMAGE_U8);
vx_image u = vxCreateImage(context, mat.cols, mat.rows, VX_DF_IMAGE_U8);
vx_image v = vxCreateImage(context, mat.cols, mat.rows, VX_DF_IMAGE_U8);

vxuChannelExtract(context, yuv, VX_CHANNEL_Y, y);
vxuChannelExtract(context, yuv, VX_CHANNEL_U, u);
vxuChannelExtract(context, yuv, VX_CHANNEL_V, v);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM