How it is possible, drawing an small axis on pattern works, but a longer axis produce totally wrong result

I tried to follow the example to draw the axis on a detected pattern.

If the axis is small it is perfectly oriented, but if I increase the size, all goes wrong.

There must be a reason for this, does someone knows why?

This is the code, where you can see the units of the axis, with 0.03 it works fine, with 3 it gets all wrong.

            img, img_sub, corners, corners_subpixel, = Find_Pattern(frame, cameraIntrinsicsPath, square_size, width,height)
            rvec, rtec = Calc_rvec_tvec(corners, cameraIntrinsicsPath, square_size, width, height)
            axis = np.float32([[0.03, 0, 0], [0, 0.03, 0], [0, 0, -0.03]]).reshape(-1, 3)
            axis_wrong = np.float32([[3, 0, 0], [0, 3, 0], [0, 0, -3]]).reshape(-1, 3)
            mtx_loaded, dist_loaded = load_coefficients(cameraIntrinsicsPath)
            imgpts, jac = cv2.projectPoints(axis, rvec, rtec, mtx_loaded, dist_loaded)
            img = draw(img, corners, imgpts)
            imgpts, jac = cv2.projectPoints(axis_wrong, rvec, rtec, mtx_loaded, dist_loaded)
            img = draw(img, corners, imgpts)
            cv2.imshow("Draw_Axisaa", img)

can you print out rvec and tvec and show us ?

Hi, thanks for the fast answer.

Sure, here it is:

rvec = [[-0.95199287]
[-0.54609878]
[-0.52713641]]
tvec = [[-0.21183996]
[ 0.02660468]
[ 0.53793701]]

1 Like

this is simply a math error in the drawing functions.

observe the screen-space coordinates you get for your axes.

your long axes are ONE HUNDRED TIMES longer than the short ones.

the end points are VERY FAR outside the drawing area.

drawing functions can fail in that situation.

use shorter axes and/or calculate the clipping of your lines with the drawing area.

Mystery solved! I imagined that something like that could be the problem, yet it surprised me and wanted to be sure about it.

Thank you!