OpenCV drawFrameAxes() 函数的问题

问题描述 投票:0回答:1

我注意到

cv::drawFrameAxes()
功能存在问题。当三重线到达图像之外很远时,这些线就会扭曲,不再与它们应该出现的轴重合。

我正在使用 OpenCV+Contrib 4.10.0 检测 charuco 板。一旦我检测并估计了它的姿态,我就会尝试绘制轴;但是,如果我改变它们的长度,即使一切保持不变,我也可以看到不同的轴。我提供了示例图像、相机参数和要重现的代码。另请查看随附的图像。轴甚至会“断开”,或者仅保留轮廓而不填充,轴长度较长,例如10.

如果我在模拟图像以及 OpenCV (opencv-python) 4.7.0.72 上执行此操作,我会得到相同的结果。

Different axis length plotted on one image

Different axis lengths

Example picture

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)

编辑:将示例图片更改为未裁剪的版本,将变量名称 mtx2 更改为 mtx,添加更多相关信息。

python opencv computer-vision camera-calibration aruco
1个回答
0
投票

这已被其他人复制并已报告为 OpenCV GitHub 上的错误。

© www.soinside.com 2019 - 2024. All rights reserved.