'cv2 findArucoMarkers sees marker from far away but doesn't draw center point until closer
The Aruco marker is detected on the img but isn't fully detected because the cv2 drawing functions don't appear on the img until I'm closer to the marker.
I also have white boarders around the marker which helps a lot but this is different.
My code works but I don't understand why cv2 doesn't draw the center point of the marker from far away when there's already a green square detecting the marker from the findArucoMarkers() function.
Here's what I see using the simulation. Doesn't see center point
See's center point when a "little" closer
import cv2
import cv2.aruco as aruco
def findArucoMarkers(img, markerSize=4, totalMarkers=50, draw=True):
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
key = getattr(aruco, f"DICT_{markerSize}X{markerSize}_{totalMarkers}")
arucoDict = aruco.Dictionary_get(key)
arucoParam = aruco.DetectorParameters_create()
aruco.detectMarkers(imgGray, arucoDict, parameters=arucoParam)
bboxs, ids, rejected = aruco.detectMarkers(imgGray, arucoDict, parameters=arucoParam)
# print(ids)
if draw:
aruco.drawDetectedMarkers(img, bboxs)
return [bboxs, ids]
def marker_finder():
# Gets img from simulator for vc to read
sendDeviceImage(robot, display)
cap = cv2.VideoCapture("display.jpg")
# Load Image
ret, img = cap.read()
findArucoMarkers(img, 4, 100, True)
arucoFound = findArucoMarkers(img)
# Loop through all the markers and augments
if len(arucoFound[0]) != 0:
for bbox, ids in zip(arucoFound[0], arucoFound[1]):
print(f"ID: {ids}")
# Get sides of marker
x, y, w, h = cv2.boundingRect(bbox)
# Get center point of b-rect
c_x = x + w // 2
c_y = y + h // 2
center = [c_x, c_y]
print(center)
radius = 2
cv2.circle(img, center, radius, (255, 255, 0), 2)
cv2.imshow("Img", img)
cv2.waitKey(33)
# Removes img from simulator
cleanup()```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
