-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .robot import arduino, comp, led, motor, power, servo, utils | ||
from .robot import arduino, comp, led, motor, power, servo, utils, vision | ||
|
||
__all__ = ['arduino', 'comp', 'led', 'motor', 'power', 'servo', 'utils'] | ||
__all__ = ['arduino', 'comp', 'led', 'motor', 'power', 'servo', 'utils', 'vision'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""An implementation of a camera board using the april_vision library.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from numpy.typing import NDArray | ||
from sbot.future.board_manager import BoardManager | ||
from sbot.marker import Marker | ||
|
||
PathLike = Path | str | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Vision: | ||
""" | ||
Virtual Camera Board for detecting fiducial markers. | ||
Additionally, it will do pose estimation, along with some calibration | ||
in order to determine the spatial positon and orientation of the markers | ||
that it has detected. | ||
""" | ||
|
||
__slots__ = ('_boards',) | ||
|
||
def __init__(self, boards: BoardManager): | ||
self._boards = boards | ||
|
||
def detect_markers( | ||
self, | ||
*, | ||
frame: NDArray | None = None, | ||
save: PathLike | None = None | ||
) -> list[Marker]: | ||
""" | ||
Capture an image and identify fiducial markers. | ||
: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. | ||
""" | ||
cam = self._boards.get_camera() | ||
if frame is None: | ||
frame = cam.capture() | ||
|
||
markers = cam.see(frame=frame) | ||
|
||
if save: | ||
cam.save(save, frame=frame, detections=markers) | ||
return [Marker.from_april_vision_marker(marker) for marker in markers] | ||
|
||
def capture(self, save: 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 | ||
""" | ||
cam = self._boards.get_camera() | ||
raw_frame = cam.capture() | ||
if save: | ||
cam.save(save, frame=raw_frame, annotated=False) | ||
return raw_frame |