Update example to annotate axis
This commit is contained in:
parent
829abd4ab5
commit
32cf8a67e1
3 changed files with 66 additions and 16 deletions
16
example.py
16
example.py
|
@ -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)
|
|
37
example/calibrations.xml
Normal file
37
example/calibrations.xml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- Sourced from https://docs.opencv.org/4.5.3/d7/d21/tutorial_interactive_calibration.html -->
|
||||||
|
<opencv_storage>
|
||||||
|
<calibrationDate>"Thu 07 Apr 2016 04:23:03 PM MSK"</calibrationDate>
|
||||||
|
<framesCount>21</framesCount>
|
||||||
|
<cameraResolution>
|
||||||
|
640 480</cameraResolution>
|
||||||
|
<cameraMatrix type_id="opencv-matrix">
|
||||||
|
<rows>3</rows>
|
||||||
|
<cols>3</cols>
|
||||||
|
<dt>d</dt>
|
||||||
|
<data>
|
||||||
|
1.2519588293098975e+03 0. 6.6684948780852471e+02 0.
|
||||||
|
1.2519588293098975e+03 3.6298123112613683e+02 0. 0. 1.</data></cameraMatrix>
|
||||||
|
<cameraMatrix_std_dev type_id="opencv-matrix">
|
||||||
|
<rows>4</rows>
|
||||||
|
<cols>1</cols>
|
||||||
|
<dt>d</dt>
|
||||||
|
<data>
|
||||||
|
0. 1.2887048808572649e+01 2.8536856683866230e+00
|
||||||
|
2.8341737483430314e+00</data></cameraMatrix_std_dev>
|
||||||
|
<dist_coeffs type_id="opencv-matrix">
|
||||||
|
<rows>1</rows>
|
||||||
|
<cols>5</cols>
|
||||||
|
<dt>d</dt>
|
||||||
|
<data>
|
||||||
|
1.3569117181595716e-01 -8.2513063822554633e-01 0. 0.
|
||||||
|
1.6412101575010554e+00</data></dist_coeffs>
|
||||||
|
<dist_coeffs_std_dev type_id="opencv-matrix">
|
||||||
|
<rows>5</rows>
|
||||||
|
<cols>1</cols>
|
||||||
|
<dt>d</dt>
|
||||||
|
<data>
|
||||||
|
1.5570675523402111e-02 8.7229075437543435e-02 0. 0.
|
||||||
|
1.8382427901856876e-01</data></dist_coeffs_std_dev>
|
||||||
|
<avg_reprojection_error>4.2691743074130178e-01</avg_reprojection_error>
|
||||||
|
</opencv_storage>
|
29
example/example.py
Executable file
29
example/example.py
Executable file
|
@ -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)
|
Loading…
Reference in a new issue