Python 3.x Aruco OpenCV示例,拒绝所有标记
我遵循这个例子 下面是我用来检测标记的代码片段。我无法理解为什么这个例子对我不起作用Python 3.x Aruco OpenCV示例,拒绝所有标记,python-3.x,opencv,image-processing,aruco,Python 3.x,Opencv,Image Processing,Aruco,我遵循这个例子 下面是我用来检测标记的代码片段。我无法理解为什么这个例子对我不起作用 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: imag
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()
有意思。你的程序没有问题。我在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字典。但是这个教程肯定有问题。我有
这是我使用的图像
这是结果。(找到的标记有绿色边框。被拒绝的候选标记有红色边框。)
您只创建了一种方法来检测aruco标记及其各自的ID。如果您想检测标记ID并用图像ID增加标记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是你从阿鲁科得到的
img是阿鲁科标记
img_aug是您希望在标记上增加的内容
draw_id=我只是在检测到的东西上画了一个id是的,即使我能用4x4_50检测到代码。。有什么想法,即使在C++中也不起作用吗?还有另一个问题:MIP_36h12 dict在opencv contrib中还不可用吗?就像我说的,我不知道为什么它不工作。我建议自己打印和拍摄一些6X6标记以进行测试。我对MIP_36h12字典一无所知。也许这就是原因。这不是问题所在。对于特定的词典,标记没有被正确检测到,因此注意:这是几年前观察到的。。阿鲁科的附属医院可能从那以后就重建了,这可能是不可见的。我只是在帮他做未来的工作