【问题标题】:Aruco OpenCV example, all markers rejectedAruco OpenCV 示例,所有标记都被拒绝
【发布时间】:2018-10-15 10:32:48
【问题描述】:

我正在学习这个例子。

OpenCV Aruco example with image

以下是我用来检测标记的代码 sn-p。我无法理解为什么该示例对我不起作用。

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-3.x opencv image-processing aruco


【解决方案1】:

有趣。你的程序没有问题。我在 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

这是我使用的图像。

结果如下。 (找到的标记有绿色边框。被拒绝的候选人有红色边框。)

【讨论】:

  • 是的,即使我能够检测到 4x4_50 的代码.. 任何想法为什么在 C++ 中也不起作用?也只是另一个查询:opencv-contrib 中是否还没有 MIP_36h12 字典?
  • 就像我说的,我不知道为什么它不起作用。我建议您自己打印和拍摄一些 6X6 标记以进行测试。我对 MIP_36h12 字典一无所知。
【解决方案2】:

您只创建了一种方法来检测 aruco 标记及其各自的 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 是您从 aruco.detectMarkers() 获得的 img 是 aruco 标记 img_aug 是您要在标记上增加的内容 draw_id = 我只是在检测到的东西上绘制了 id

【讨论】:

  • 这不是问题所在。没有正确检测到特定词典的标记
  • 另请注意:这是几年前观察到的。aruco 依赖关系可能已经重建,这可能是不可观察的。
【解决方案3】:

我遇到了同样的问题。我通过使用函数cv::flip 翻转输入图像垫来解决它。

【讨论】:

  • 今后,在写单行字时,请考虑添加评论而不是答案。
猜你喜欢
  • 1970-01-01
  • 2021-11-11
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-21
相关资源
最近更新 更多