Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'cv2.aruco' has no attribute 'detectMarkers' python

I'm using python and pycharm on a iMac.

Line of code is:

corners, _, _ = cv2.aruco.detectMarkers(img, aruco_dict, parameters=parameters)

Error msg is:

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

I've looked every where and haven't found an answer...

The other "problems" is there are several instances of cv2.circle(img, (int(x), int(y)), 5, (0, 0, 255), -1), where there are these carets ^^^^^^ marks underneath the word circle in yellow, seems like where all the carets are underneath all the function names(imread,aruco,arcLength,minAreaRect,boxPoints,polylines,putText. The ^^^^^^ are like underscore _ but ^ instead)

Any answers to this?? I've tried about every YouTube videos and internet search to resolve this..but am not able to find the answer. I have no/little experience with this. By the way, I'm 75 years old, just trying something new. Thanks to all for the assistance

like image 467
Rc3375 Avatar asked Jun 16 '26 12:06

Rc3375


1 Answers

The issue is due to aruco api changes in opencv version 4.7.0. The below code handles both older and newer opencv versions.

import cv2
from packaging import version  # Installed with setuptools, so should already be installed in your env.


if version.parse(cv2.__version__) >= version.parse("4.7.0"):
    dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_250)
    detectorParams = cv2.aruco.DetectorParameters()
    detector = cv2.aruco.ArucoDetector(dictionary, detectorParams)
    marker_corners, marker_ids, rejected_candidates = detector.detectMarkers(image)
else:
    dictionary = cv2.aruco.Dictionary_get(cv2.aruco.DICT_5X5_250)
    detectorParams = cv2.aruco.DetectorParameters_create()
    marker_corners, marker_ids, rejected_candidates = cv2.aruco.detectMarkers(
        image, dictionary, parameters=detectorParams
    )
like image 100
saurabheights Avatar answered Jun 18 '26 02:06

saurabheights



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!