【问题标题】:AttributeError: module 'cv2.aruco' has no attribute 'Dictionary_get'AttributeError: 模块 \'cv2.aruco\' 没有属性 \'Dictionary_get\'
【发布时间】:2022-12-31 03:09:11
【问题描述】:

AttributeError:模块“cv2.aruco”没有属性“Dictionary_get”

即使在安装之后

opencv-python opencv-contrib-python

import numpy as np
import cv2, PIL
from cv2 import aruco
import matplotlib.pyplot as plt
import matplotlib as mpl
import pandas as pd

vid = cv2.VideoCapture(0)

while (True):

    ret, frame = vid.read()
    #cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
    parameters =  aruco.DetectorParameters()
    corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
    frame_markers = aruco.drawDetectedMarkers(frame.copy(), corners, ids)

    plt.figure()
    plt.imshow(frame_markers)
    for i in range(len(ids)):
        c = corners[i][0]
        plt.plot([c[:, 0].mean()], [c[:, 1].mean()], "o", label = "id={0}".format(ids[i]))
    plt.legend()
    plt.show()
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()

查找和标记 aruco 的正常示例

【问题讨论】:

    标签: opencv aruco


    【解决方案1】:

    从新版本安装旧版本的 opencv-contrib-python 后,它工作正常

    pip install opencv-contrib-python==4.6.0.66
    

    https://pypi.org/project/opencv-contrib-python/4.6.0.66/

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 2022-06-15
      • 2017-11-22
      • 2019-07-25
      • 2017-11-21
      • 2021-02-17
      • 2019-11-13
      • 2018-11-13
      • 2019-05-28
      相关资源
      最近更新 更多