From f7a6bb5db2ceeebdfea64462ae3cddf1e9be9df6 Mon Sep 17 00:00:00 2001 From: cching_io Date: Sat, 19 Sep 2026 15:57:57 +0800 Subject: [PATCH 1/2] integrate camera by using library --- apriltag_cc.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 apriltag_cc.py diff --git a/apriltag_cc.py b/apriltag_cc.py new file mode 100644 index 00000000..76f913cb --- /dev/null +++ b/apriltag_cc.py @@ -0,0 +1,87 @@ + +import cv2 +from apriltag import apriltag + +# Create detector once +detector = apriltag("tag36h11") + +# Open default camera +cap = cv2.VideoCapture(0) + +cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) +cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720) + +while True: + ok, frame = cap.read() + + if not ok: + print("Failed to read camera frame") + break + + # AprilTag detector expects grayscale image + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + + # Detect AprilTags + detections = detector.detect(gray) + + for detection in detections: + + # Your library returns a dictionary: + # { + # 'hamming': ..., + # 'margin': ..., + # 'id': ..., + # 'center': ..., + # 'lb-rb-rt-lt': ..., + # 'homography': ... + # } + + corners = detection["lb-rb-rt-lt"].astype(int) + tag_id = detection["id"] + center = detection["center"].astype(int) + + # Draw tag boundary + cv2.polylines( + frame, + [corners], + True, + (0, 255, 0), + 2 + ) + + # Draw tag center + cv2.circle( + frame, + tuple(center), + 5, + (0, 0, 255), + -1 + ) + + # Display Tag ID + x, y = corners[0] + + cv2.putText( + frame, + f"ID: {tag_id}", + (x, y - 10), + cv2.FONT_HERSHEY_SIMPLEX, + 0.7, + (0, 255, 0), + 2 + ) + + print( + f"Tag ID: {tag_id}, " + f"Center: {center}, " + f"Decision Margin: {detection['margin']:.2f}" + ) + + cv2.imshow("AprilTag Detection", frame) + + # Press Q to exit + if cv2.waitKey(1) & 0xFF == ord("q"): + break + +cap.release() +cv2.destroyAllWindows() From 74116cabc0f1efccebab540339e3eb8c8146098f Mon Sep 17 00:00:00 2001 From: cching_io Date: Sat, 19 Sep 2026 16:08:22 +0800 Subject: [PATCH 2/2] add deploy.md --- deploy.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 deploy.md diff --git a/deploy.md b/deploy.md new file mode 100644 index 00000000..dc4db771 --- /dev/null +++ b/deploy.md @@ -0,0 +1,45 @@ +# Local deployment + +## Build and install + +Clone the repository and enter it: + +```bash +git clone +cd apriltag +``` + +Configure a Release build, then build and install it: + +```bash +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build --target install +``` + +The default install prefix is usually `/usr/local`. If your account cannot write +there, run the install command with the appropriate administrator privileges, or +configure CMake with a writable `CMAKE_INSTALL_PREFIX`. + +## Select the camera + +Before running, set the camera index in `apriltag_cc.py` to the correct device: + +```python +cap = cv2.VideoCapture(0) +``` + +Replace `0` with the index for the desired camera. On Linux, camera device nodes +are typically `/dev/video0`, `/dev/video1`, and so on; the intended camera may +not be index `0`. + +## Run + +If your default Python package path is `/usr/local/lib/python3.12/dist-packages/`, +run the script with the installed package directory included in `PYTHONPATH`: + +```bash +PYTHONPATH=/usr/local/lib/python3.12/site-packages python3 apriltag_cc.py +``` + +Adjust the Python version and package path if your installation uses different +locations.