Skip to content

Commit c36cf72

Browse files
committed
fix: replaced apriltags with pupil_apriltags
1 parent 733be6b commit c36cf72

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

.github/workflows/cpp.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ jobs:
2222
key: ${{ runner.os }}-apt-${{ hashFiles('debian_deps.txt') }}
2323
restore-keys: |
2424
${{ runner.os }}-apt-
25-
- name: Cache build directory
26-
uses: actions/cache@v4
27-
with:
28-
path: build
29-
key: ${{ runner.os }}-build-cpp-${{ hashFiles('src/**', 'include/**', 'CMakeLists.txt', 'pyproject.toml') }}
30-
restore-keys: |
31-
${{ runner.os }}-build-cpp-
3225
- name: Install dependencies
3326
run: sudo apt install $(cat debian_deps.txt)
3427
- name: Set up Python 3.11

extensions/rcs_panda/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2525
set(CMAKE_CXX_STANDARD 20)
2626
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2727
set(CMAKE_CXX_EXTENSIONS OFF)
28+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
2829

2930
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3031

extensions/rcs_realsense/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description="RCS realsense module"
99
dependencies = [
1010
"rcs>=0.5.0",
1111
"pyrealsense2~=2.55.1",
12-
"apriltag==0.0.16",
12+
"pupil_apriltags",
1313
"diskcache",
1414
]
1515
maintainers = [

extensions/rcs_realsense/src/rcs_realsense/calibration.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from pathlib import Path
55
from time import sleep
66

7-
import apriltag
7+
# CHANGE 1: New Import
8+
from pupil_apriltags import Detector
9+
810
import cv2
911
import diskcache as dc
1012
import numpy as np
@@ -40,7 +42,7 @@ def calibrate(
4042
input()
4143
tries = 3
4244
while len(samples) < 10 and tries > 0:
43-
logger.info("not enought frames in recorded, waiting 2 seconds...")
45+
logger.info("not enough frames in recorded, waiting 2 seconds...")
4446
tries = -1
4547
sleep(2)
4648
if tries == 0:
@@ -51,7 +53,7 @@ def calibrate(
5153
with lock:
5254
for sample in samples:
5355
frames.append(sample.camera.color.data.copy())
54-
print(frames)
56+
# print(frames) # Removed print for cleaner logs, optional
5557

5658
_, tag_to_cam = get_average_marker_pose(frames, intrinsics=intrinsics, calib_tag_id=9, show_live_window=False)
5759

@@ -71,9 +73,9 @@ def get_average_marker_pose(
7173
calib_tag_id,
7274
show_live_window,
7375
):
74-
# create detector
75-
options = apriltag.DetectorOptions(families="tag25h9")
76-
detector = apriltag.Detector(options=options)
76+
# CHANGE 2: Simplified Initialization
77+
# No "DetectorOptions" object needed anymore.
78+
detector = Detector(families="tag25h9")
7779

7880
# make while loop with tqdm
7981
poses = []
@@ -97,6 +99,7 @@ def get_average_marker_pose(
9799
camera_matrix = intrinsics[:3, :3]
98100

99101
if show_live_window:
102+
# Note: pose[:3, :3] works because we construct the 4x4 matrix in get_marker_pose below
100103
cv2.drawFrameAxes(frame, camera_matrix, None, pose[:3, :3], pose[:3, 3], 0.1) # type: ignore
101104
# show frame
102105
cv2.imshow("frame", frame)
@@ -120,7 +123,20 @@ def get_average_marker_pose(
120123

121124
def get_marker_pose(calib_tag_id, detector, intrinsics, frame):
122125
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
123-
detections = detector.detect(gray)
126+
127+
# CHANGE 3: Pose estimation happens INSIDE .detect()
128+
# We must extract camera params first to pass them here
129+
fx = intrinsics[0, 0]
130+
fy = intrinsics[1, 1]
131+
cx = intrinsics[0, 2]
132+
cy = intrinsics[1, 2]
133+
134+
detections = detector.detect(
135+
gray,
136+
estimate_tag_pose=True,
137+
camera_params=[fx, fy, cx, cy],
138+
tag_size=0.1
139+
)
124140

125141
# count detections
126142
n_det = 0
@@ -138,20 +154,10 @@ def get_marker_pose(calib_tag_id, detector, intrinsics, frame):
138154
if marker_det is None:
139155
return None, None
140156

141-
fx = intrinsics[0, 0]
142-
fy = intrinsics[1, 1]
143-
cx = intrinsics[0, 2]
144-
cy = intrinsics[1, 2]
145-
146-
pose, _, _ = detector.detection_pose(
147-
marker_det,
148-
camera_params=(
149-
fx,
150-
fy,
151-
cx,
152-
cy,
153-
),
154-
tag_size=0.1,
155-
)
157+
# CHANGE 4: Construct 4x4 Matrix manually
158+
# pupil-apriltags gives us R (3x3) and t (3x1). We must stack them.
159+
pose = np.eye(4)
160+
pose[:3, :3] = marker_det.pose_R
161+
pose[:3, 3] = marker_det.pose_t.ravel() # ravel() flattens the (3,1) array to (3,)
156162

157163
return marker_det, pose

0 commit comments

Comments
 (0)