Projecting a 2D point from marker to image with computed homography

I have a planar marker where I run the SIFT algorithm to extract functions. Then I start the detector to find this marker in the scene and extract the functions again. I match points and extract homography from matched pairs with OpenCV using findHomography() .

Now I want to project the 2D points found in the marker with the calculated homography in order to compare positions with the 3D points measured from the scene and calculate the repro error . I got confused with pixel coordinates, centimeters, gauge matrices, I don’t know what transformations should be done in the first place.

Does anyone know a link to this or can explain the method?

+6
source share
1 answer

If you call the homography matrix H, the camera matrix K (necessary for conversion to pixels) will be something like this, depending on your resolution.

 Mat K= Mat::zeros(3,3,CV_32FC1); K.at<float>(0,0)=500.0f; K.at<float>(0,2)=320.0f; // width/2 K.at<float>(1,1)=500.0f; K.at<float>(1,2)=240.0f; // height/2 K.at<float>(2,2)=1.0f; 

If your marker points are 2D vector points:

 vector<Point2f> marker_point; //containing coordinates in centimeters 

then the projection will be like this: with the result, there will be a 3D point in pixel coordinates.

 Mat point(3,1,CV_32FC1); point.at<float>(0) = marker_point.x; point.at<float>(1) = marker_point.y; point.at<float>(2) = 1.0f; point = H* point; point = point/point.at<float>(2); //Normalize point = K* point; //to pixels 
+6
source

Source: https://habr.com/ru/post/923653/


All Articles