From 32cf8a67e18442ccc6b3f4c21416dd6ad2ab5e70 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 16 Nov 2022 14:08:03 +0000 Subject: [PATCH] Update example to annotate axis --- example.py | 16 ---------------- example/calibrations.xml | 37 +++++++++++++++++++++++++++++++++++++ example/example.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 16 deletions(-) delete mode 100755 example.py create mode 100644 example/calibrations.xml create mode 100755 example/example.py diff --git a/example.py b/example.py deleted file mode 100755 index 55fea92..0000000 --- a/example.py +++ /dev/null @@ -1,16 +0,0 @@ -import cv2 -import cv2.aruco as aruco - -aruco_dict = aruco.Dictionary_get(aruco.DICT_APRILTAG_36H11) -parameters = aruco.DetectorParameters_create() - -cap = cv2.VideoCapture(0) - -while True: - _, frame = cap.read() - corners, ids, rejects = aruco.detectMarkers(frame, aruco_dict, parameters=parameters) - aruco.drawDetectedMarkers(frame, corners, ids) - aruco.drawDetectedMarkers(frame, rejects, borderColor=(0, 0, 255)) - - cv2.imshow('preview', frame) - cv2.waitKey(1) diff --git a/example/calibrations.xml b/example/calibrations.xml new file mode 100644 index 0000000..c0f2413 --- /dev/null +++ b/example/calibrations.xml @@ -0,0 +1,37 @@ + + + +"Thu 07 Apr 2016 04:23:03 PM MSK" +21 + + 640 480 + + 3 + 3 +
d
+ + 1.2519588293098975e+03 0. 6.6684948780852471e+02 0. + 1.2519588293098975e+03 3.6298123112613683e+02 0. 0. 1.
+ + 4 + 1 +
d
+ + 0. 1.2887048808572649e+01 2.8536856683866230e+00 + 2.8341737483430314e+00
+ + 1 + 5 +
d
+ + 1.3569117181595716e-01 -8.2513063822554633e-01 0. 0. + 1.6412101575010554e+00
+ + 5 + 1 +
d
+ + 1.5570675523402111e-02 8.7229075437543435e-02 0. 0. + 1.8382427901856876e-01
+4.2691743074130178e-01 +
diff --git a/example/example.py b/example/example.py new file mode 100755 index 0000000..028b5be --- /dev/null +++ b/example/example.py @@ -0,0 +1,29 @@ +from pathlib import Path + +import cv2 +from zoloto.cameras.camera import Camera +from zoloto.marker_type import MarkerType + + +class AxisAnnotatingCamera(Camera): + def _annotate_frame(self, frame): + """ + Annotate axis onto the image too. + + This does perform the detection twice, but for a demo this is fine. + """ + super()._annotate_frame(frame) + for marker in self.process_frame_eager(frame=frame): + cv2.drawFrameAxes( + frame, + self.calibration_params.camera_matrix, + self.calibration_params.distance_coefficients, + marker._rvec, + marker._tvec, + self._marker_size + ) + + +with AxisAnnotatingCamera(0, marker_type=MarkerType.APRILTAG_36H11, marker_size=100, calibration_file=Path(__file__).parent / "calibrations.xml") as camera: + print("Starting preview... Press 'q' to exit.") # noqa: T001 + camera.show(annotate=True)