ArUco Markers not working, AttributeError

Fairly new to Python and coding in general.

I’ve started a uni project that requires the use of ArUco markers, however I cannot get the code to work or any ArUco code for that matter.
I have gone through every ‘solution’ I can come across but no good.
I have installed the correct modules and the pip cv contrib installs that should allow it to work but i’m always getting the same error…

import cv2 as cv
from cv2 import aruco

# dictionary to specify type of the marker
marker_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)

# MARKER_ID = 0
MARKER_SIZE = 400  # pixels

# generating unique IDs using for loop
for id in range(20):  # genereting 20 markers
    # using funtion to draw a marker
    marker_image = aruco.generateImageMarker(marker_dict, id, MARKER_SIZE)
    cv.imshow("img", marker_image)
    cv.imwrite(f"markers/marker_{id}.png", marker_image)
    # cv.waitKey(0)
    # break

After running a ArUco generator or detection code I get this error.

If anyone has anything I can try to fix it, please let me know.

Thank you for posting your code, but please don’t post images of error messages.

As for your error:

Hi Steven,

Thanks for your response, however the post hasn’t helped me.
I have installed the suggested version of cv, changed the functions.

and this is the error I consistently get.
AttributeError: 'function' object has no attribute 'getPredefinedDictionary'

I’ve also tried running the code mentioned in that post and I get other errors such as:
VideoCapture(0) has no argument, nor can I find a fix for this.

To solve the problem follow the instructions below:
Install:
pip install opencv-python
pip install opencv-contrib-python

If you already have it installed, just update them to the latest version:
pip install --upgrade opencv-python
pip install --upgrade opencv-contrib-python

After doing the above, try this code:
import cv2
import matplotlib.pyplot as plt

Select the ArUco dictionary you want to use

aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)

generate the bookmark

id = 24 # This is the identifier of the bookmark, you can change it to whatever you need
img_size = 700 # Define the size of the final image
marker_img = cv2.aruco.generateImageMarker(aruco_dict, id, img_size)

show marker

plt.imshow(marker_img, cmap=‘gray’, interpolation=“nearest”)
plt.axis(“off”)
plt.show()

save the image

cv2.imwrite(“aruco{}.png”.format(id), marker_img)