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.

WarpPerspective API in TIOVX, Also issue with vxuWarpPerspective API

Hi TI, 

I am trying to transform my image to bird eye view, for that, I initially wrote a code in python and generated the Homography matrix by adjusting the source and destination points. The generated matrix from getPerspectiveTransform function of OpenCV then inserted into the  vxuWarpPerspective and got the output. The result is incorrect and doesn't match with the OpenCV output. Kindly guide me how to solve this issue? Is there any way to extract the homography within OpenVX rather OpenCV? Is there tiovx provided API for this purpose? Thank you.

With best regards,

H.M. Owais

  • There is no way to extract the homograph within OpenVX as other tools and libraries (like OpenCV as you mentioned) should be able to provide this.  When you say that it doesn't match, is it completely wrong, or slightly off.  Have you confirmed that the matrix is programmed with the right data types and is not transposed accidentally?

    As an alternative, you can use the tivxVpacLdcNode as well to get a bird eye view.  It has also a perspective matrix, or alternatively, you can use a remap table (mesh).  This would be faster than the OpenVX perspective correction functions since it is hardware accelerated.  The mesh table can also be downsampled in order to save memory bandwidth.  Of course if perspective matrix gives proper result without using mesh table, that is best from a ddr bandwidth point of view.

  • Hi Jesse,

    Thank you for your reply. I have tried to attach the code via txt file but it gives some error. So, I have added the code below. I have tested this code, seems like something is wrong with the API. However, I am not sure as I am a beginner in OpenVX. Would you please have a look at it and let me know where the mistake is?

    /*********************************Code Starts**************************************************************************/

    #include <stdio.h>
    #include <VX/vx.h>
    #include <VX/vxu.h>
    #include <utility.h>


    /** \brief Input file name */
    #define IN_FILE_NAME "convert1.bmp"

    /** \brief Output file name */
    #define OUT_FILE_NAME "vx_test_warp_image_out.bmp"

    void vx_test_warp_image()
    {
    /**
    * - Define objects that we wish to create in the OpenVX application.
    *
    * A vx_context object is defined which is used as input parameter for all subesquent
    * OpenVX object create APIs
    * \code
    */
    vx_context context;
    vx_image in_image;
    vx_image out_image;
    vx_uint32 width, height;

    printf(" vx_test_warp_image: Tutorial Started !!! \n");


    /**
    * - Create OpenVX context.
    *
    * This MUST be done first before any OpenVX API call.
    * The context that is returned is used as input for subsequent OpenVX APIs
    * \code
    */
    context = vxCreateContext();
    /** \endcode */

    printf(" Loading file %s ...\n", IN_FILE_NAME);
    /**
    * - Create image object.
    *
    * Follow the comments in create_image_from_file() to see
    * how a vx_image object is created and filled with RGB data from BMP file \ref IN_FILE_NAME
    * \code
    */
    in_image = create_image_from_file(context, IN_FILE_NAME, vx_true_e);
    /** \endcode */

    vxSetReferenceName((vx_reference)in_image, "INPUT");
    /**
    * - Show image attributes.
    *
    * Follow the comments in show_image_attributes() to see
    * how image attributes are queried and displayed.
    * \code
    */
    //show_image_attributes(in_image);
    /** \endcode */


    vxQueryImage(in_image, VX_IMAGE_WIDTH, &width, sizeof(vx_uint32));
    vxQueryImage(in_image, VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));

    printf("Image height %d \n", height);
    printf("Image width %d \n", width);

    out_image = vxCreateImage(context, 640, 480, VX_DF_IMAGE_U8);
    /** \endcode */

    vxSetReferenceName((vx_reference)out_image, "OUTPUT");
    /**
    * - Show image attributes.
    *
    * Follow the comments in show_image_attributes() to see
    * how image attributes are queried and displayed.
    * \code
    */
    show_image_attributes(out_image);
    /** \endcode */
    vx_float32 mat[3][3] = {
    {-7.24049501, 1.88882479, 0.00314804131}, // ’x’ coefficients
    {-30.12009190, 83.56985830, -0.0978822762}, // ’y’ coefficients
    {2963.73020, 8772.522060, 1}, // ’offsets’
    };

    vx_matrix matrix = vxCreateMatrix(context, VX_TYPE_FLOAT32,3,3);

    vxCopyMatrix(matrix, mat, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);

    vxuWarpPerspective(context, in_image, matrix, VX_INTERPOLATION_BILINEAR, out_image);

    printf(" Saving to file %s ...\n", OUT_FILE_NAME);

    /**
    * - Save image object to bitmap file \ref OUT_FILE_NAME.
    *
    * Follow the comments in save_image_to_file() to see
    * how data in vx_image object is accessed to store pixel values from the image object to
    * BMP file \ref OUT_FILE_NAME
    * \code
    */
    save_image_to_file(OUT_FILE_NAME, out_image);
    printf("OUTPUTFile %s", OUT_FILE_NAME);
    /** \endcode */


    /**
    * - Release image object.
    *
    * Since we are done with using this image object, release it
    * \code
    */

    vxReleaseMatrix(&matrix);
    vxReleaseImage(&in_image);
    vxReleaseImage(&out_image);
    /** \endcode */

    /**
    * - Release context object.
    *
    * Since we are done using OpenVX context, release it.
    * No further OpenVX API calls should be done, until a context is again created using
    * vxCreateContext()
    * \code
    */
    vxReleaseContext(&context);
    /** \endcode */

    printf(" vx_test_warp_image: Tutorial Done !!! \n");
    printf(" \n");


    }

    /****************************************** Code ends*******************************************/

    Looking forward to hearing from you. Thank you.

    With best regards,

    H.M. Owais

  • H.M. Owais,

    I don't see any issues in this code.  So I wonder if the problem is in the warp matrix you have chosen.  I have done a quick check using your warp coefficients against the equation from the OpenVX spec. See attached spreadsheet.  Does this back mapping of coordinates look right?

    warp_check.xlsx