python-3.x - Aruco OpenCV 示例,所有标记均被拒绝

标签 python-3.x opencv image-processing aruco

我正在关注这个例子。

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()

Local Run of above code, all markers rejected.

最佳答案

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

这是我使用的图片。

source image

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

result image

关于python-3.x - Aruco OpenCV 示例,所有标记均被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52814747/

相关文章:

c++ - 使用-lopencv_videoio的Opencv编译不起作用

python - CV2 图像错误 : error: (-215:Assertion failed) ! 函数 'cv::resize' 中的 ssize.empty()

matlab如何将图像旋转90度?

Java - 在圆的边缘、顶部和底部绘制文本

python - 如何使用 numpy 有效地制作脉冲噪声图像?

c++ - 如何在 QLabel 中显示捕获图像

python - 在 python 中创建一个新类型

python - 在 OSX 中为 python3 安装 opencv3

python - 在 Python 中格式化驱动器

python - 在 python 子进程中捕获 logger.info 输出?