Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update camera docs for new API #606

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions programming/vision/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For information on markers, see the [markers page](./markers).

## Camera

The interface to the vision system is through the camera, accessible through `robot.camera`, there are three functions available on the camera object:
The interface to the vision system is through the camera, accessible through `robot.camera`, there are two functions available on the camera object:

see
: Take a photo using the webcam, and return a list of [`Marker`](#marker) instances, each of which describes one of the markers that were found in the image.
Expand All @@ -47,17 +47,6 @@ Taking images while moving will cause them to be blurry, which will cause marker
Try pausing movement while taking an image.
</div>

save
: Take a photo using the webcam, draw a box around the detected markers and save it to the provided location.

~~~~~ python
from sr.robot3 import *
robot = Robot()

# `robot.usbkey` is the path to your USB drive
robot.camera.save(robot.usbkey / "initial-view.jpg")
~~~~~

capture
: Take a photo using the webcam, and return the image data as an OpenCV array.

Expand Down Expand Up @@ -95,6 +84,31 @@ robot.camera.save(robot.usbkey / "photo.jpg", frame=frame)
~~~~~


### Saving camera output

You can also save a snapshot of what your webcam is currently seeing. This can be useful to debug your code.

This is done by adding the `save` parameter to the `see` or `capture` functions.
The parameter should be the filename to where you want to save the image.

If used with the `see` function, every marker that your robot can see will have a square annotated around it, with a red dot indicating the top left corner of the marker.
The ID of every marker is also written next to it.

Snapshots are saved to your USB drive, and can be viewed on another computer.

```python
from sr.robot3 import *

robot = Robot()

# Save a snapshot of what the camera is currently seeing
frame = robot.camera.capture(save="snapshot.jpg")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Is it worth adding a warning or something that images are overwritten, and potentially to use sensible naming to help understand which image is from when?


# Save a snapshot of what the camera is currently seeing with markers annotated
markers = robot.camera.see(save="annotated-snapshot.jpg")
```


## Marker

A `Marker` object contains information about a detected marker.
Expand Down