Reputation: 49
I noticed an issue with the cv::drawFrameAxes()
function. When the triad lines reach far outside of the image, the lines are distorted, no longer coincident with the axes as they should appear.
I was working on detecting charuco boards using OpenCV+Contrib 4.10.0. Once I have detected and estimated its pose, I am trying to plot the axis; however, I can see different axis if I change their lengths even if everything remains the same. I am providing a sample image, camera params and code to reproduce. Take a look a the attached images as well. The axis even 'break', or keeps only the outline without the fill, at longer axis length, e.g. 10.
I get the same results if I do this on simulated images as well as OpenCV (opencv-python) 4.7.0.72.
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
# camera params after calibration
mtx = np.array([[3341.0930071 , 0. , 2020.04757797],
[ 0. , 3332.54238818, 1108.10670945],
[ 0. , 0. , 1. ]])
dist = np.array([-0.10474984, 0.04565679, 0.00948721, 0. , 0. ])
img_rgb = cv2.imread("some img")
img_rgb = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
img = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
# board info
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_100)
board = cv2.aruco.CharucoBoard((7, 5), 0.055, 0.041, dictionary)
params = cv2.aruco.DetectorParameters()
detector = cv2.aruco.ArucoDetector(dictionary, params)
# detect markers and charuco corners
marker_corners, marker_ids, rejectedCandidates = detector.detectMarkers(img)
ret, charucoCorners, charucoIds = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, img, board)
ret, rvec, tvec = cv2.aruco.estimatePoseCharucoBoard(charucoCorners, charucoIds, board, mtx, dist, None, None)
# start plotting
axis_size = 0.1
result_short = cv2.drawFrameAxes(np.copy(img_rgb), mtx, dist, rvec, tvec, axis_size)
axis_size = 5
result_long = cv2.drawFrameAxes(np.copy(img_rgb), mtx, dist, rvec, tvec, axis_size)
# plot
plt.subplot(1,2,1)
plt.imshow(result_short)
plt.subplot(1,2,2)
plt.imshow(result_long)
plt.show()
result_both = cv2.drawFrameAxes(np.copy(img_rgb), mtx, dist, rvec, tvec, 0.2)
result_both = cv2.drawFrameAxes(result_both, mtx, dist, rvec, tvec, 2)
Edit: Changed the example picture to an uncropped version, changed variable name mtx2 to mtx, added more relevant info.
Upvotes: -1
Views: 276
Reputation: 49
This has been reproduced by others and have been reported as a bug on OpenCV GitHub.
Upvotes: 0