/
sat1988
/
AutonomousFlight
Обзор
Документация
Войти
/
sat1988
/
AutonomousFlight
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
train.py
38 строк
1 KB
Oleg Chorakaev
Signed-off-by: Oleg Chorakaev <olegchorakaev@yandex.ru>
31 июл 2025, 00:26
31 июл 2025, 00:26
c2629b9
Код
Авторство
О чём код?
import cv2 import pyapriltags from lxml.html.defs import frame_tags cap = cv2.VideoCapture(0) detector = pyapriltags.Detector(searchpath=["apriltags"], families="tag36h11") while True: ret, frame = cap.read() #frame = cv2.resize(frame, (320,240)) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) results = detector.detect(gray) #print("[INFO] {} total AprilTags detected".format(len(results))) for r in results: #print(r.tag_id) print(r.homography) (ptA, ptB, ptC, ptD) = r.corners ptB = (int(ptB[0]), int(ptB[1])) ptC = (int(ptC[0]), int(ptC[1])) ptD = (int(ptD[0]), int(ptD[1])) ptA = (int(ptA[0]), int(ptA[1])) # draw the bounding box of the AprilTag detection cv2.line(frame, ptA, ptB, (0, 255, 0), 2) cv2.line(frame, ptB, ptC, (0, 255, 0), 2) cv2.line(frame, ptC, ptD, (0, 255, 0), 2) cv2.line(frame, ptD, ptA, (0, 255, 0), 2) # draw the center (x, y)-coordinates of the AprilTag (cX, cY) = (int(r.center[0]), int(r.center[1])) cv2.circle(frame, (cX, cY), 5, (0, 0, 255), -1) # draw the tag family on the image tagFamily = r.tag_family.decode("utf-8") cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), cv2.FONT_HERSHEY_SIMPLEX,0.5,(0, 255, 0),2) cv2.imshow("video", frame) # Show an image on the screen if cv2.waitKey(1) == 27: # Exit if the ESC key is pressed break cap.release() cv2.destroyAllWindows()