OpenCV Code which I try cannot detect some ArUco's

import numpy as np
import cv2

    "DICT_4X4_50": cv2.aruco.DICT_4X4_50,
    "DICT_4X4_100": cv2.aruco.DICT_4X4_100,
#In fact there are more dictionary keys than written above. I deleted them to shorten the question.

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)
  , (cX, cY), 4, (0, 0, 255), -1)
            cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX,
                0.5, (0, 255, 0), 2)
            print("[Inference] ArUco marker ID: {}".format(markerID))
    return image

img = cv2.imread('markers.jpg', 1) 

#the first parameter will change according to the name of the photo

aruco_type = ["DICT_4X4_50",
for i in aruco_type:
    arucoDict = cv2.aruco.getPredefinedDictionary(ARUCO_DICT[i])

    arucoParams = cv2.aruco.DetectorParameters()

    corners, ids, rejected = cv2.aruco.ArucoDetector(arucoDict, arucoParams).detectMarkers(img)

    detected_markers = aruco_display(corners, ids, rejected, img)

    cv2.imshow("Image", detected_markers)



This code can detect most of codes but there is still problem due to not detecting some ArUco’s like that:

How can I solve this issue?

I think if it can detect some of them, I don’t understand why it cannot detect ArUco’s on same image.

where are those markers from?

why do you think they’re arucos?

Actually, I found first image on Internet randomly, so as you say, some of them might not be a ArUco, because it can detect every ArUco which was generated on a site where the features of the codes can be generted.

In fact my aim is to detect nine ArTags (or ArUcos) in second images, a ROS package (ar_track_alvar) provides me to detect those images easily, but I search if there is another way to detect those images without ROS.

AR markers aren’t 2D barcodes. if you need 2D barcodes, using AR markers is a mistake.

“aruco” is not a synonym for “AR marker”, not even for “square marker with bits in it”. aruco is a specific type of marker, with specific requirements for what’s inside of the square.

you seem to be looking for a “barcode scanner” type library for AR markers. OpenCV doesn’t do that. you need to know which markers you’re dealing with.