Question: need a fix for AttributeError: module ' cv 2 . aruco' has no attribute 'Dictionary _ get' import numpy as np import time import cv

need a fix for AttributeError: module 'cv2.aruco' has no attribute 'Dictionary_get'
import numpy as np
import time
import cv2
ARUCO_DICT ={
"DICT_4x4_50": cv2.aruco.DICT_4X4_50,
"DICT_4x4_100": cv2.aruco.DICT_4X4_100,
"DICT_4x4_250": cv2.aruco.DICT_4X4_250,
"DICT_4x4_1000": cv2.aruco.DICT_4X4_1000,
"DICT_5x5_50": cv2.aruco.DICT_5X5_50,
"DICT_5x5_100": cv2.aruco.DICT_5X5_100,
"DICT_5x5_250": cv2.aruco.DICT_5X5_250,
"DICT_5x5_1000": cv2.aruco.DICT_5X5_1000,
"DICT_6x6_50": cv2.aruco.DICT_6X6_50,
"DICT_6x6_100": cv2.aruco.DICT_6X6_100,
"DICT_6x6_250": cv2.aruco.DICT_6X6_250,
"DICT_6x6_1000": cv2.aruco.DICT_6X6_1000,
"DICT_7x7_50": cv2.aruco.DICT_7X7_50,
"DICT_7x7_100": cv2.aruco.DICT_7X7_100,
"DICT_7x7_250": cv2.aruco.DICT_7X7_250,
"DICT_7x7_1000": cv2.aruco.DICT_7X7_1000,
"DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
"DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
"DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
"DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
"DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
}
def aruco_display (corners, ids, rejected, image):
if len(corners)>0:
ids = ids.flatten()
for(markerCorner, markerID) in zip(corners,ids):
corners = markerCorner.reshape((4,2))
(topLeft, topRight, bottomRight, bottomLeft)= corners
topRight =(int(topRight[0]),int(topRight[1]))
bottomRight =(int(bottomRight[0]),int(bottomRight[1]))
bottomLeft =(int(bottomLeft[0]),int(bottomLeft[1]))
topLeft =(int(topLeft[0]),int(topLeft[1]))
cv2.line(image, topLeft, topRight, (0,255,0),2)
cv2.line(image, topRight, bottomRight, (0,255,0),2)
cv2.line(image, bottomRight, bottomLeft, (0.255,0),2)
cv2.line(image, bottomLeft, topLeft, (0.255,0),2)
cX = int((topLeft[0]+ bottomRight[0])/2.0)
cY = int((topLeft[1]+ bottomRight[1])/2.0)
cv2.circle(image,(cX,cY),4,(0,0,255),-1)
cv2.putText(image, str(markerID),(topLeft[0],topLeft[1]-10), cv2.FONT_HERSHEY(0.5,(0,255,0),2))
print("[Inference] ArUco marker ID: {}".format(markerID))
return image
aruco_type = "DICT_5x5_100"
arucoDict = cv2.aruco.Dictionary_get(ARUCO_DICT[aruco_type])
arucoParams = cv2.aruco.DetectorParameters_create()
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
while cap.isOpened():
ret, img = cap.read()
h,w,_= img.shape
width =1000
height = int(width*(h/w))
img = cv2.resize(img,(width,height), interpolation = cv2.INTER_CUBIC)
corners, ids, rejected = cv2.aruco.detectMarkers(img, arucoDict, parameters=arucoParams)
detected_markers = aruco_display(corners, ids, rejected, img)
cv2.imshow("Image", detected_markers)
key = cv2.waitKey(1) & 0xFF
if key == ord ("q"):
break
cv2.destroyAllWindows()
cap.release()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!