python - 将 ArUco 的姿势轴绘制到错误的位置
问题描述
我正在研究检测 ArUco 标记并根据这些标记做一些事情的图像处理项目。当视频或图像中只有一个标记时,一切正常,但是当我放置另一个标记时,第二个 ArUco 标记的姿势(轴)打印到错误的位置,而不是标记的中心。请查看我分享的屏幕截图以便更好地理解。
带有 id[2] 的标记很好。姿势轴被绘制到标记的中心。但是,id为1的标记的姿势轴被绘制到某个随机点。
这是检测 ArUco 标记并绘制轴的代码部分。
while True:
ret, frame = cap.read()
# Operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Change grayscale
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250) # Specify marker size as 4x4, 5x5, 6x6
parameters = aruco.DetectorParameters_create() # Marker detection parameters
# Lists of ids and the corners beloning to each marker
corners, ids, rejected_img_points = aruco.detectMarkers(gray, aruco_dict,
parameters=parameters,
cameraMatrix=matrix_coefficients,
distCoeff=distortion_coefficients)
try:
if np.all(ids is not None): # If there are markers found by detector
for i in range(0, len(ids)): # Iterate in markers
# Estimate pose of each marker and return the values rvec and tvec---different from camera coefficients
rvec, tvec, markerPoints = aruco.estimatePoseSingleMarkers(corners[i], 0.02, matrix_coefficients,
distortion_coefficients)
(rvec - tvec).any() # get rid of that nasty numpy value array error
aruco.drawDetectedMarkers(frame, corners) # Draw A square around the markers
aruco.drawAxis(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01) # Draw axis
c_x = (corners[i][0][0][0] + corners[i][0][1][0] + corners[i][0][2][0] + corners[i][0][3][0]) / 4 # X coordinate of marker's center
c_y = (corners[i][0][0][1] + corners[i][0][1][1] + corners[i][0][2][1] + corners[i][0][3][1]) / 4 # Y coordinate of marker's center
cv2.putText(frame, "id"+str(ids[i]), (int(c_x), int(c_y)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (50,225,250), 2)
except:
if ids is None or len(ids) == 0:
print("******************************************************")
print("*************** Marker Detection Failed **************")
print("******************************************************")
解决方案
推荐阅读
- c# - 当我尝试重新发送时,VSTO Outlook 加载项电子邮件仍保留在发件箱中
- python - 同一图表上的相同查询在 Neptune 与 Gremlify 上返回不同的结果
- excel - 来自 VBA 的 DLL 声明行中的编译器错误“未定义用户定义的类型”
- installation - Hyperledger Fabric - 示例 - 2.2.0 平台特定结构二进制文件不可下载
- sql - 用 100 万条记录填充表
- spring-boot - 如何使用带有自定义标头的 OAuth1.0 使用 Spring Boot 对 API 进行身份验证
- java - Cassandra 节点拒绝加入集群“Compaction Executor”错误
- android - 如何使用 kotlin 从另一个类调用同伴内部的扩展对象?
- file-io - 使用特定的 strftime 格式时无法打开 Outfile 错误 (NSIS 3.0.5) !define /date "NOW"
- firebase - 在等待之后我应该返回一个承诺吗?