Skip to content

Commit a59e7d4

Browse files
authored
Merge pull request #606 from srobo/sr2025-api
Update camera docs for new API
2 parents 54d27d1 + 8cd2faf commit a59e7d4

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

programming/vision/index.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For information on markers, see the [markers page](./markers).
2020

2121
## Camera
2222

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

2525
see
2626
: 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.
@@ -47,17 +47,6 @@ Taking images while moving will cause them to be blurry, which will cause marker
4747
Try pausing movement while taking an image.
4848
</div>
4949

50-
save
51-
: Take a photo using the webcam, draw a box around the detected markers and save it to the provided location.
52-
53-
~~~~~ python
54-
from sr.robot3 import *
55-
robot = Robot()
56-
57-
# `robot.usbkey` is the path to your USB drive
58-
robot.camera.save(robot.usbkey / "initial-view.jpg")
59-
~~~~~
60-
6150
capture
6251
: Take a photo using the webcam, and return the image data as an OpenCV array.
6352

@@ -95,6 +84,35 @@ robot.camera.save(robot.usbkey / "photo.jpg", frame=frame)
9584
~~~~~
9685

9786

87+
### Saving camera output
88+
89+
You can also save a snapshot of what your webcam is currently seeing. This can be useful to debug your code.
90+
91+
This is done by adding the `save` parameter to the `see` or `capture` functions.
92+
The parameter should be the filename to where you want to save the image.
93+
94+
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.
95+
The ID of every marker is also written next to it.
96+
97+
Snapshots are saved to your USB drive, and can be viewed on another computer.
98+
99+
<div class="warning">
100+
When saving images, make sure to use a unique filename each time, otherwise the previous image will be overwritten.
101+
</div>
102+
103+
```python
104+
from sr.robot3 import *
105+
106+
robot = Robot()
107+
108+
# Save a snapshot of what the camera is currently seeing
109+
frame = robot.camera.capture(save="snapshot.jpg")
110+
111+
# Save a snapshot of what the camera is currently seeing with markers annotated
112+
markers = robot.camera.see(save="annotated-snapshot.jpg")
113+
```
114+
115+
98116
## Marker
99117

100118
A `Marker` object contains information about a detected marker.

0 commit comments

Comments
 (0)