0

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 ?

Muhammad Ali
  • 418
  • 6
  • 20
  • Please provide the full code that reproduce the problem. In general your code looks correct, except that it will be safer to use `mat.step` instead of `mat.cols * sizeof(vx_uint8)*3`. – vinograd47 Apr 14 '16 at 18:57
  • BTW, RGB has only one plane, since it is interleaved format. – vinograd47 Apr 14 '16 at 19:01
  • Note, that for some YUV formats, U and V planes have smaller dimension that Y plane. – vinograd47 Apr 19 '16 at 08:50

1 Answers1

0

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);
Sorcerer
  • 190
  • 7