Search code examples
c++opencvremap

Can I get the point position using remap in OpenCV


I have taken a photo A using an RGB camera. And I know the position of a point g in photo A. The camera needs to do a camera calibration. Now I want to know the position of point g after calibration. I am using the code as following, but I want to get the point position, not image. How can I do that? Can you give me some advice?

initUndistortRectifyMap(
        cameraMatrix,   
        distCoeffs,     
        Mat(),      
        Mat(),      
        Size(640, 480),
        CV_32FC1,      
        map1, map2);  
 remap(A, B, map1, map2, cv::INTER_LINEAR);  

Point2f g = Point2f(...,...);//i want to get the new position of the point not image B   

Solution

  • Just get coordinates using maps:

    x,y - coordinates after (not before),as pasbi correctly noticed in comments, mapping.

    (map1(y,x),map2(y,x)) - coordinates before mapping

    In other words:

    • map1.at<float>(y,x) contains source x coordinates for each destination point p(x,y).

    • map2.at<float>(y,x) contains source y coordinates for each destination point p(x,y).

    See documentation on remap function.