Search code examples
opencvscalingmat

Calculation of coordinates of point on a scaled Mat image in OpenCv


If I have a Mat image object (OpenCV) whose size is 960*720, on which I have calculated the coordinates of a Point object, and then I scale this Mat image, and its new size is 640*480, how can I find the new coordinates of the Point?


Solution

  • A point (x,y) in the original matrix will be mapped to (x',y') in the new matrix by

    (x',y') = 2*(x,y)/3.
    

    Reducing that to an OpenCV function we have:

    cv::Point scale_point(cv::Point p) // p is location in 960*720 Mat
    {
        return 2 * p / 3;   // return location in 640*480 Mat
    }