Minimum aruco marker size

70 views Asked by At

Can someone explain what the minimum aruco marker size is in pixels? Also, which of the detector parameters would make detecting smaller marker sizes more reliable with perspective changes? As I decrease the size in pixels, detectMarkers just stops working. DetectorParameters has a lot of parameters to tune but I haven't seen as documentation that explains ranges of values to try or which parameters would help with the detection of smaller markers.

import cv2
import cv2.aruco as aruco
import numpy as np
import matplotlib.pyplot as plt

marker_id = 37
image_size = 8 

# Draw the ArUco marker
dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)

image = aruco.generateImageMarker(dictionary, marker_id, image_size)

# Define the padding size
padding_size = 4

# Create a larger array with zeros
padded_image = np.ones((image_size + 2 * padding_size, image_size + 2 * padding_size), dtype=np.uint8)*255

# Copy the original image to the center of the padded array
padded_image[padding_size:image_size + padding_size, padding_size:image_size + padding_size] = image

# Detect ArUco markers in the scene
arucoParams = cv2.aruco.DetectorParameters()
# arucoParams.adaptiveThreshWinSizeMin = 10
# arucoParams.detectInvertedMarker = True
corners, ids, rejected_points = cv2.aruco.detectMarkers(padded_image, dictionary, parameters=arucoParams)

# Print the results for debugging
print("Detected Corners:", corners)
print("Detected IDs:", ids)
print("Rejected Points:", rejected_points)

if ids:

    xs = corners[0][:,:,0]
    ys = corners[0][:,:,1]

    minX, maxX = np.min(xs), np.max(xs)
    minY, maxY = np.min(ys), np.max(ys)

    width, height = abs(maxX-minX), abs(maxY-minY)

    print("Width of the box:", width)
    print("Height of the box:", height)

    from matplotlib.collections import PolyCollection
    poly = PolyCollection(corners[0], facecolors = 'red', edgecolors='k', linewidth=1)
    alpha_vals = np.array([0.2, 0.8])
    poly.set_alpha(alpha_vals)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    ax.imshow(padded_image,cmap='gray')
    ax.add_collection(poly)
    pad = 2
    plt.xlim(minX-pad, maxX+pad)
    plt.ylim(minY-pad, maxY+pad)
    plt.show()
0

There are 0 answers