-
Notifications
You must be signed in to change notification settings - Fork 0
Aruco Kod #8
Copy link
Copy link
Open
Description
import cv2
import cv2.aruco as aruco
import numpy as np
Biblioteka prepoznaje markere od 0-49
aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)
parameters = aruco.DetectorParameters()
detector = aruco.ArucoDetector(aruco_dict, parameters)
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
Promeniti broj 0 sa drugim brojem u slucaju da kamera ne radi
try:
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detekcija markera
corners, ids, rejected = detector.detectMarkers(gray)
if ids is not None:
# Crtaj sve markere
aruco.drawDetectedMarkers(frame, corners, ids)
# Sortiranje markera
id_x_pairs = []
for corner, marker_id in zip(corners, ids.flatten()):
cx = np.mean(corner[0][:, 0])
id_x_pairs.append((cx, marker_id))
id_x_pairs.sort(key=lambda x: x[0])
sorted_ids = [pair[1] for pair in id_x_pairs]
output = ", ".join([f"{mid}" for mid in sorted_ids])
print(output)
cv2.imshow("Frame", frame) # Pokazuje sliku kamere
if cv2.waitKey(1) & 0xFF == ord('q'): # Program se skroz gasi na dugme 'q'
break
finally:
cap.release()
cv2.destroyAllWindows()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels