Examples¶
Annotate Image¶
import sys
from pathlib import Path
from zoloto.cameras.file import ImageFileCamera
from zoloto.marker_type import MarkerType
class TestCamera(ImageFileCamera):
marker_type = MarkerType.DICT_6X6_50
def get_marker_size(self, marker_id: int) -> int:
return 100
with TestCamera(Path(sys.argv[1])) as camera:
camera.save_frame(Path(sys.argv[2]), annotate=True)
print( # noqa: T001
"Saw {} markers in this image".format(len(camera.get_visible_markers()))
)
Count Markers¶
from zoloto.cameras.camera import Camera
from zoloto.marker_type import MarkerType
class TestCamera(Camera):
marker_type = MarkerType.DICT_6X6_50
def get_marker_size(self, marker_id: int) -> int:
return 100
camera = TestCamera(0)
while True:
marker_ids = camera.get_visible_markers()
print("I can see {} markers".format(len(marker_ids)), end="\r") # noqa: T001
Identify Markers¶
import sys
from pathlib import Path
from zoloto.cameras.file import VideoFileCamera
from zoloto.marker_type import MarkerType
def process_marker_type(current_marker_type: MarkerType) -> None:
class TestCamera(VideoFileCamera):
marker_type = current_marker_type
def get_marker_size(self, marker_id: int) -> int:
return 100
found_markers = False
with TestCamera(Path(sys.argv[1])) as camera:
for i, frame in enumerate(camera):
print(current_marker_type, i, end="\r") # noqa: T001
if i % 3 == 0:
if camera.get_visible_markers(frame=frame):
found_markers = True
break
print(current_marker_type, found_markers) # noqa: T001
def main() -> None:
for marker_type in MarkerType:
process_marker_type(marker_type)
if __name__ == "__main__":
main()
Visual Demo¶
from chrono import Timer
from numpy import ndarray
from zoloto.cameras.camera import Camera
from zoloto.marker_type import MarkerType
from zoloto.viewer import CameraViewer
class TestCamera(Camera):
marker_type = MarkerType.DICT_6X6_50
def get_marker_size(self, marker_id: int) -> int:
return 100
class Viewer(CameraViewer):
def on_frame(self, frame: ndarray) -> ndarray:
with Timer() as annotate_timer:
camera._annotate_frame(frame)
print(round(annotate_timer.elapsed * 1000), end="\r") # noqa: T001
return frame
camera = TestCamera(0)
Viewer(camera).start()