This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Vision SDK: TIDL OD ObjectDrawLink Access to RGB values of pixels in a detection

Hi,

I have modified TIDL OD example in order to detect traffic lights. However, the model is unable to detect whether traffic lights are red or greeen.

What I intend to do is to analyze R,G,B values of the pixels in bounding box (using pObjectDataDesc coordinates) and see if the light is red or green.

In order to do so, I think I need to be able to access R,G,B values of pixels in objectDrawLink_algPlugin.c, preferably in function AlgorithmLink_objectDrawObjects(...).

How do I achieve such a thing? Any guidance is greately appreciated.

Thanks in advance for the help.

  • I will check with TIDL team & get back

  • Hi,

    To draw the bounding box around the detected object, we are using coordinates (

    @param xPos
    Location of the detected object in pixels along X direction.

    @param yPos
    Location of the detected object in pixels along Y direction.

    @param objWidth
    Width of the located object in pixels. Does not indicate actual
    width of the object.

    @param objHeight
    Width of the located object in pixels. Does not indicate actual
    height of the object.

    )

    So using these coordinates you can analyze the RGB values in the buffer & make sure the data format is in RGB or YUV

    Thanks

    Gaviraju

  • Hi,

    Thanks for the information, but I am already aware what is provided with pObjectDesc type.

    I am interested in accessing the buffer from inside the file objectDrawLink_algPlugin.c.
    Could you please tell me which variable is the buffer, and how R,G,B values are identified with buffer, to start with ?
    Or redirect me to a guide which explains it.

    Thanks.

  • Hi,

    pObjectDrawObj->drawBufAddr[0] = (UInt32)pVideoBuffer->bufAddr[0];
    pObjectDrawObj->drawBufAddr[1] = (UInt32)pVideoBuffer->bufAddr[1];

    This is the buffer address you can use "drawBufAddr" or pVideoBuffer->bufAddr[0] variable to access the data.

    The data format seems in YUV, not in RGB. So you may need to convert from YUV to RGB.

    Thanks

    Gaviraju

  • Hi,
    Thanks, that's great help.
    Could you also redirect me to other files/examples where pixels (Y,U,V / R,G,B) are extracted/analyzed with drawBufAddr?
    I have investigated a few examples such as AlgorithmLink_copyTrafficSign(..), but I can't figure out what to do in my particular case:

    To start with, I have the following based on AlgorithmLink_copyTrafficSign(..). Could help me in tailoring this, as I am still a beginner with TIDL Buffer manipulation?

    Int32 AlgorithmLink_detectRedOrGreenLight(
        UInt8 *bufAddrY,
        UInt8 *bufAddrC,
        UInt32 pitchY,
        UInt32 pitchC,
        UInt32 bufWidth,
        UInt32 bufHeight,
        UInt32 startX,
        UInt32 startY
        )
    {
        UInt32 copyWidth, copyHeight;

        / align to multiple of 2, since data format is YUV420 /
        startX = SystemUtils_floor(startX, 2);
        startY = SystemUtils_floor(startY, 2);

        / clip the copy area to limit within buffer area /
        copyWidth = bufWidth;
        copyHeight = bufHeight;

        if(startX > bufWidth || startY > bufHeight)
        {
            / Nothing to copy in this case /
            return 0;
        }

        if(startX+copyWidth > bufWidth)
        {
            copyWidth = bufWidth - startX;
        }

        if(startY+copyHeight > bufHeight)
        {
            copyHeight = bufHeight - startY;
        }

        / adjust input buffer pointer to start location /
        bufAddrY = bufAddrY + pitchY*startY + startX;
        bufAddrC = bufAddrC + pitchC*startY/2 + startX;

        return 0;
    }

    What does bufAddrY, bufAddrC, pitchY, pitchC mean, and how do I access Y,U,V values?
    After extracting Y,U,V of a pixel , I'm thinking I can then use:

    void RGBfromYUV(double& R, double& G, double& B, double Y, double U, double V)
    {
      R = 1.164 * Y             + 1.596 * V;
      G = 1.164 * Y - 0.392 * U - 0.813 * V;
      B = 1.164 * Y + 2.017 * U;
    }

    Thanks.

  • Hi,

    Now you know the output TIDL buffer address, co-ordinates & function to convert from YUV to RGB, so recommend you to understand the YUV420 data format first then convert RGB, there will lot of information available in the google.

    Thanks

    Gaviraju