Skip to content

Commit

Permalink
Merge pull request #343 from sourcebots/new-camera-api
Browse files Browse the repository at this point in the history
New camera API
  • Loading branch information
WillB97 authored Jul 1, 2024
2 parents d87bf96 + aad7d47 commit dc0cd61
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dynamic = ["version"]
requires-python = ">=3.8"
dependencies = [
"pyserial >=3,<4",
"april_vision >=2.0.2,<3",
"april_vision==2.2.0a1",
"typing-extensions; python_version<'3.10'",
]
classifiers = [
Expand Down
38 changes: 22 additions & 16 deletions sbot/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .marker import Marker
from .utils import Board, BoardIdentity

PathLike = Union[Path, str]
LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -99,36 +100,41 @@ def close(self) -> None:
"""
self._cam.close()

def see(self, *, eager: bool = True, frame: Optional[NDArray] = None) -> List[Marker]:
def see(
self,
*,
frame: Union[NDArray, None] = None,
save: Union[PathLike, None] = None,
) -> List[Marker]:
"""
Capture an image and identify fiducial markers.
:param eager: Process the pose estimations of markers immediately,
currently unused.
:param frame: An image to detect markers in, instead of capturing a new one,
:param save: If given, save the annotated frame to the path.
This is given a JPEG extension if none is provided.
:returns: list of markers that the camera could see.
"""
if frame is None:
frame = self._cam.capture()

markers = self._cam.see(frame=frame)

if save:
self._cam.save(save, frame=frame, detections=markers)
return [Marker.from_april_vision_marker(marker) for marker in markers]

def capture(self) -> NDArray:
def capture(self, *, save: Union[PathLike, None] = None) -> NDArray:
"""
Get the raw image data from the camera.
:param save: If given, save the unannotated frame to the path.
This is given a JPEG extension if none is provided.
:returns: Camera pixel data
"""
return self._cam.capture()

def save(self, path: Union[Path, str], *, frame: Optional[NDArray] = None) -> None:
"""
Save an annotated image to a path.
:param path: The path to save the image to,
this is given a JPEG extension if none is provided.
:param frame: An image to annotate and save, instead of capturing a new one,
defaults to None
"""
self._cam.save(path, frame=frame)
raw_frame = self._cam.capture()
if save:
self._cam.save(save, frame=raw_frame, annotated=False)
return raw_frame

def _set_marker_sizes(
self,
Expand Down

0 comments on commit dc0cd61

Please sign in to comment.