【发布时间】:2022-01-20 10:18:45
【问题描述】:
我尝试检测图像上的 Aruco 代码。我在 Docker 的 Jupyter Notebook 工作,所以我使用的是图像,而不是视频,并且无法访问某些功能(例如 cv2.imshow('QueryImage', QueryImg))
我准备了这个脚本:
import numpy
import cv2
import cv2.aruco as aruco
from matplotlib import pyplot as plt
im = cv2.imread('ar3.jpg')
ARUCO_PARAMETERS = aruco.DetectorParameters_create()
# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show()
im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
corners, ids, rejectedImgPoints = aruco.detectMarkers(im, ARUCO_DICT, parameters=ARUCO_PARAMETERS)
if ids is not None and len(ids) == 5:
for i, corner in zip(ids, corners):
print('ID: {}; Corners: {}'.format(i, corner))
im = aruco.drawDetectedMarkers(im, corners, borderColor=(0, 0, 255))
else:
print("NONE")
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show()
并使用带有标记的简单图像:
但我的代码没有看到这些标记。
代码、图像或标记有问题?你有什么想法吗?
更新: 我使用此代码生成标记:
import cv2
import cv2.aruco as aruco
# Create gridboard, which is a set of Aruco markers
# the following call gets a board of markers 5 wide X 7 tall
gridboard = aruco.GridBoard_create(
markersX=5,
markersY=7,
markerLength=0.04,
markerSeparation=0.01,
dictionary=aruco.Dictionary_get(aruco.DICT_5X5_1000))
# Create an image from the gridboard
img = gridboard.draw(outSize=(988, 1400))
cv2.imwrite("test_gridboard.jpg", img)
我得到了这张图片: 接下来,我从该图像中复制标记并将其粘贴到图像中(如您在第一张图像中看到的那样)。此外,我更换了字典:
# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)
但此代码仍然无法检测到标记。此外,来自 Google Play 的任何应用程序也无法检测到它们。 我用应用测试这张图片:
【问题讨论】:
-
外面的两个坏了,因为“安静区”是强制性的。
-
顺便说一句...您的代码是 5x5。你注意到了吗?
-
@ChristophRackwitz 谢谢你的信息,我更新了我的帖子。也许你知道我现在能做什么?
-
如果您缺少 imshow,请使用此
from google.colab.patches import cv_imshow-- 既然您修复了 6x6/5x5 问题,至少应该找到两个标记 -- 您应该认真考虑这一行:if ids is not None and len(ids) == 5:以及当不是的情况时会发生什么。 -
谢谢@ChristophRackwitz,现在一切正常;)我不知道为什么我忘记了带有'if'的编辑行