Harikrishnan M
Harikrishnan M

Reputation: 235

AttributeError: module 'cv2.aruco' has no attribute 'Dictionary_get'

AttributeError: module 'cv2.aruco' has no attribute 'Dictionary_get'

even after installing

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

normal example for finding and marking aruco

Upvotes: 16

Views: 56440

Answers (3)

Evdokimos Theodoridis
Evdokimos Theodoridis

Reputation: 133

I use Python 3.8, try this:

pip uninstall opencv-contrib-python opencv-python

and then install:

pip install opencv-contrib-python==4.7.0.68 opencv-python==4.7.0.68

Upvotes: 0

not7CD
not7CD

Reputation: 584

API changed for 4.7.x, I have updated a small snippet. Now you need to instantiate ArucoDetector object.

import cv2 as cv

dictionary = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_250)
parameters =  cv.aruco.DetectorParameters()
detector = cv.aruco.ArucoDetector(dictionary, parameters)

frame = cv.imread(...)

markerCorners, markerIds, rejectedCandidates = detector.detectMarkers(frame)

Upvotes: 40

Harikrishnan M
Harikrishnan M

Reputation: 235

After installing an older version of opencv-contrib-python from the new version it worked fine

pip install opencv-contrib-python==4.6.0.66

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

Upvotes: 7

Related Questions