From e74442b27e32daa4292a08336e9a5b0212c68307 Mon Sep 17 00:00:00 2001 From: Jeffrey E Erickson Date: Sat, 29 Jun 2024 13:54:22 -0500 Subject: [PATCH] apriltag test info --- LICENSE | 3 ++- detection_object | 16 ++++++++++++++ test.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 detection_object create mode 100644 test.py diff --git a/LICENSE b/LICENSE index 66c3dbc..466e5f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2024 Recoil Robotics +Copyright (c) 2024 FRC 9577 Recoil Robotics +Copyright (c) 2024 Central Texas FRC Alliane, Inc. dba Innovatiion Treehouse Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/detection_object b/detection_object new file mode 100644 index 0000000..00b3ce4 --- /dev/null +++ b/detection_object @@ -0,0 +1,16 @@ +Detection object: +tag_family = b'tag36h11' +tag_id = 2 +hamming = 0 +decision_margin = 44.62813949584961 +homography = [[ 2.69612366e+01 1.67040375e+00 7.11355833e+02] + [-7.04108208e-01 2.86574596e+01 1.15765181e+02] + [-1.03034204e-03 2.04496354e-03 1.00000000e+00]] +center = [711.35583265 115.7651814 ] +corners = [[683.96160889 144.68180847] + [739.23742676 143.57286072] + [738.91906738 86.67015076] + [683.41760254 87.90101624]] +pose_R = None +pose_t = None +pose_err = None \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..51edb63 --- /dev/null +++ b/test.py @@ -0,0 +1,55 @@ +import cv2 +import pupil_apriltags as apriltag + + +# define a video capture object +vid = cv2.VideoCapture(0) + +detector = apriltag.Detector() +first_image = True +while(True): + + # Capture the video frame + # by frame + ret, frame = vid.read() + + # convert the frame to grayscale + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + results = detector.detect(gray) + + # loop over the AprilTag detection results + for r in results: + # extract the bounding box (x, y)-coordinates for the AprilTag + # and convert each of the (x, y)-coordinate pairs to integers + (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 = str(r.tag_id) + if first_image: + print(r) + first_image=False + cv2.putText(frame, tagFamily, (cX + 20, cY + 20 ), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 2) + cv2.imshow("Image",frame) + # the 'q' button is set as the + # quitting button you may use any + # desired button of your choice + if cv2.waitKey(1) & 0xFF == ord('q'): + break + +# After the loop release the cap object +vid.release() +# Destroy all the windows +cv2.destroyAllWindows() \ No newline at end of file