Search code examples
pythonopencvaruco

OpenCV ArUco marker detection


I am attempting to detect an ArUco marker on my image, but OpenCV is not detecting the marker. I believe it may potentially be because of low resolution, but I'm not sure.

I used this tool to generate a 4x4 ID.

The following is my code:

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

def find_marker(img, x1, y1, x2, y2):
    img = img[y1:y2, x1:x2]
    img = imutils.resize(img, width=500)
    cv2.imshow('result', img)
    cv2.waitKey(0)
    corners, ids, rej = cv2.aruco.detectMarkers(img, aruco_dict)
    print(corners)
    print(ids)

When running the code, this is the image that cv.imshow is showing me: enter image description here

As you can see, there is a lower resolution ArUco label, but it should still be readable. However, the code prints out None for the ids and an empty () for corners.


Solution

  • You need to have a white border around all four edges of the marker.

    The detection first check for square shapes in the image. If you do not have a white border around the marker, it cannot detect the outer square shape of the marker.