Skip to content

Commit

Permalink
Merge pull request #606 from srobo/sr2025-api
Browse files Browse the repository at this point in the history
Update camera docs for new API
  • Loading branch information
WillB97 authored Sep 3, 2024
2 parents 54d27d1 + 8cd2faf commit a59e7d4
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 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,35 @@ 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.

<div class="warning">
When saving images, make sure to use a unique filename each time, otherwise the previous image will be overwritten.
</div>

```python
from sr.robot3 import *

robot = Robot()

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

# 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

0 comments on commit a59e7d4

Please sign in to comment.