84 lines
No EOL
3.4 KiB
Python
84 lines
No EOL
3.4 KiB
Python
from imutils.video import VideoStream
|
|
import argparse
|
|
import imutils
|
|
import time
|
|
import cv2
|
|
import sys
|
|
import numpy
|
|
|
|
ARUCO_DICT = {
|
|
"DICT_4X4_50": cv2.aruco.DICT_4X4_50,
|
|
"DICT_4X4_100": cv2.aruco.DICT_4X4_100,
|
|
"DICT_4X4_250": cv2.aruco.DICT_4X4_250,
|
|
"DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
|
|
"DICT_5X5_50": cv2.aruco.DICT_5X5_50,
|
|
"DICT_5X5_100": cv2.aruco.DICT_5X5_100,
|
|
"DICT_5X5_250": cv2.aruco.DICT_5X5_250,
|
|
"DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
|
|
"DICT_6X6_50": cv2.aruco.DICT_6X6_50,
|
|
"DICT_6X6_100": cv2.aruco.DICT_6X6_100,
|
|
"DICT_6X6_250": cv2.aruco.DICT_6X6_250,
|
|
"DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
|
|
"DICT_7X7_50": cv2.aruco.DICT_7X7_50,
|
|
"DICT_7X7_100": cv2.aruco.DICT_7X7_100,
|
|
"DICT_7X7_250": cv2.aruco.DICT_7X7_250,
|
|
"DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
|
|
"DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
|
|
"DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
|
|
"DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
|
|
"DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
|
|
"DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
|
|
}
|
|
|
|
cap = cv2.VideoCapture(0) # id 0 camera standart systeme
|
|
aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_ARUCO_ORIGINAL) #style TO DO utiliser celui de la compete
|
|
aruco_params = cv2.aruco.DetectorParameters_create()
|
|
if (cap.isOpened() == False):
|
|
raise("error opening video input")
|
|
|
|
while cap.isOpened() == True:
|
|
ret, frame = cap.read()
|
|
|
|
if ret == True:
|
|
|
|
frame = imutils.resize(frame, width=1000) # resize chaque frame en 1000x1000
|
|
(corners, ids, rejected) = cv2.aruco.detectMarkers(frame,aruco_dict, parameters=aruco_params) # corners position dans la frame des coins du code
|
|
# id de touts les codes detectées(peut être liste de int)
|
|
#
|
|
if len(corners) > 0: #si code détectée,
|
|
ids = ids.flatten() # affiche dans le frame video la position des codes et leur ID
|
|
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(frame, topLeft, topRight, (0, 255, 0), 2)
|
|
cv2.line(frame, topRight, bottomRight, (0, 255, 0), 2)
|
|
cv2.line(frame, bottomRight, bottomLeft, (0, 255, 0), 2)
|
|
cv2.line(frame, bottomLeft, topLeft, (0, 255, 0), 2)
|
|
|
|
cX = int((topLeft[0] + bottomRight[0]) / 2.0)
|
|
cY = int((topLeft[1] + bottomRight[1]) / 2.0)
|
|
cv2.circle(frame, (cX, cY), 4, (0, 0, 255), -1)
|
|
|
|
cv2.putText(frame, str(markerID),
|
|
(topLeft[0], topLeft[1] - 15),
|
|
cv2.FONT_HERSHEY_SIMPLEX,
|
|
0.5, (0, 255, 0), 2)
|
|
|
|
cv2.imshow("Frame", frame) # affiche frame dans l'ecran
|
|
|
|
|
|
cv2.imshow('Frame',frame)
|
|
if cv2.waitKey(25) & 0XFF == ord('q'): # fermeture fenetre video
|
|
break
|
|
else:
|
|
break
|
|
|
|
cap.release()
|
|
cv2.destroyAllWindows()
|
|
|
|
#si le code ne detecte pas, vérifier bien le type de aruco code et s'il est entourée d'un carrée blanc |