我正在遵循这个例子。
OpenCV Aruco example with image
下面是我用来检测标记的代码片段。我不能理解为什么这个例子对我不起作用。
import numpy as np
import cv2
import cv2.aruco as aruco
import os
im_names = filter(lambda x: x.endswith('.png'),
[f for f in os.listdir('local_vids_ims')])
for imn in im_names:
image = cv2.imread('local_vids_ims/' + imn)
# image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
parameters = aruco.DetectorParameters_create()
corners, ids, rejectedImgPoints = aruco.detectMarkers(
image, aruco_dict, parameters=parameters)
print(corners, ids, rejectedImgPoints)
# aruco.drawDetectedMarkers(image, corners)
aruco.drawDetectedMarkers(image, rejectedImgPoints)
cv2.imshow('gray_im', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

发布于 2018-10-16 04:51:15
有意思的。你的程序没有问题。我在Python和C++中尝试了同样的方法,得到了和你一样的结果。所以我尝试了不同的图像,并取得了成功。
这是我的程序。它基本上与您的相同,但请注意,我使用的是不同的字典。
import numpy as np
import cv2
import cv2.aruco as aruco
image = cv2.imread("52814747.png")
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
parameters = aruco.DetectorParameters_create()
corners, ids, rejectedImgPoints = aruco.detectMarkers(
image, aruco_dict, parameters=parameters)
print(corners, ids, rejectedImgPoints)
aruco.drawDetectedMarkers(image, corners, ids)
aruco.drawDetectedMarkers(image, rejectedImgPoints, borderColor=(100, 0, 240))
cv2.imshow('so52814747', image)
cv2.waitKey(0)
cv2.destroyAllWindows()我不知道是6X6字典有问题,还是源图像没有足够的分辨率来使用6x6字典。但是这个教程肯定有问题。我已经reported the issue on GitHub了。
这是我使用的图片。

这就是结果。(找到的标记具有绿色边框。被拒绝的候选人有红色边框。)

发布于 2021-06-15 18:35:17
您只创建了一个方法来检测aruco标记及其各自的ID。
def augment_marker(bbox , ids , img , img_aug , draw_id=True):
tl = bbox[0][0][0], bbox[0][0][1] # top left
tr = bbox[0][1][0], bbox[0][1][1]
br = bbox[0][2][0], bbox[0][2][1] # bottom left
bl = bbox[0][3][0], bbox[0][3][1]
h , w , c = img_aug.shape
pts1 = np.array([tl,tr,br,bl])
pts2 = np.float32([[0,0],[w,0],[w,h],[0,h]])
matrix, _ = cv2.findHomography(pts2,pts1)
imgout = cv2.warpPerspective(img_aug , matrix ,
(img.shape[1],img.shape[0]))
# here the above imgout will just wrapy the marker and make the
background full black
# so now just want to overlay the marker part and make the
environment
real
# step 1 : making the marker area alone black
cv2.fillConvexPoly(img , pts1.astype(int),(0,0,0))
imgout = img + imgout其中,bbox是您从aruco.detectMarkers()获得的内容img是aruco标记img_aug是您想要在标记draw_id = just I made以在检测到的事物上绘制id的内容
发布于 2021-11-18 06:40:59
我遇到了同样的问题。我通过使用函数cv::flip翻转输入图像垫来解决这个问题。
https://stackoverflow.com/questions/52814747
复制相似问题