Skip to content

Commit d8c1d64

Browse files
authored
DOCS-3471: Update camera.md remove stream from Go camera interface (#3942)
1 parent 0e8fef6 commit d8c1d64

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

docs/dev/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,7 @@ for d in detections:
478478
```go
479479
// Get image from camera stream on construction site
480480
myCamera, err := camera.FromRobot(machine, "construction-site-cam")
481-
camStream, err := myCamera.Stream(context.Background())
482-
img, release, err := camStream.Next(context.Background())
483-
defer release()
481+
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCamera)
484482

485483
// Use machine learning model to gather information from the image
486484
visService, err := vision.FromRobot(machine, "hardhat_detector")
@@ -494,6 +492,8 @@ for i := 0; i < len(detections); i++ {
494492
}
495493
```
496494

495+
Be sure to import `"go.viam.com/rdk/utils"` at the beginning of your file.
496+
497497
{{% /tab %}}
498498
{{< /tabs >}}
499499

docs/dev/reference/apis/components/camera.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The camera API allows you to give commands to your [camera components](/operate/
1616

1717
The API for camera components allows you to:
1818

19-
- Request single images or a stream in 2D color, or display z-depth.
19+
- Request single images in 2D color, or display z-depth.
2020
- Request a point cloud.
2121
Each 3D point cloud image consists of a set of coordinates (x,y,z) representing depth in mm.
2222

docs/operate/reference/services/vision/color_detector.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ import (
211211
"go.viam.com/rdk/config"
212212
"go.viam.com/rdk/services/vision"
213213
"go.viam.com/rdk/components/camera"
214+
"go.viam.com/rdk/utils"
214215
)
215216

216217
// Grab the camera from the machine
@@ -237,12 +238,11 @@ if len(directDetections) > 0 {
237238
// If you need to store the image, get the image first
238239
// and then run detections on it. This process is slower:
239240

240-
// Get the stream from a camera
241-
camStream, err := myCam.Stream(context.Background())
242-
243-
// Get an image from the camera stream
244-
img, release, err := camStream.Next(context.Background())
245-
defer release()
241+
// Get an image from the camera decoded as an image.Image
242+
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
243+
if err != nil {
244+
logger.Fatalf("Could not decode image from camera: %v", err)
245+
}
246246

247247
// Apply the color classifier to the image from your camera (configured as "cam1")
248248
detectionsFromImage, err := myDetector.Detections(context.Background(), img, nil)

docs/operate/reference/services/vision/mlmodel.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ import (
342342
"go.viam.com/rdk/config"
343343
"go.viam.com/rdk/services/vision"
344344
"go.viam.com/rdk/components/camera"
345+
"go.viam.com/rdk/utils"
345346
)
346347

347348
cameraName := "cam1"
@@ -367,12 +368,11 @@ if len(directDetections) > 0 {
367368
// If you need to store the image, get the image first
368369
// and then run detections on it. This process is slower:
369370

370-
// Get the stream from a camera
371-
camStream, err := myCam.Stream(context.Background())
372-
373-
// Get an image from the camera stream
374-
img, release, err := camStream.Next(context.Background())
375-
defer release()
371+
// Get an image from the camera decoded as an image.Image
372+
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
373+
if err != nil {
374+
logger.Fatalf("Could not decode image from camera: %v", err)
375+
}
376376

377377
// Apply the color classifier to the image from your camera (configured as "cam1")
378378
detectionsFromImage, err := myDetector.Detections(context.Background(), img, nil)
@@ -423,6 +423,7 @@ import (
423423
"go.viam.com/rdk/config"
424424
"go.viam.com/rdk/services/vision"
425425
"go.viam.com/rdk/components/camera"
426+
"go.viam.com/rdk/utils"
426427
)
427428

428429
cameraName := "cam1"
@@ -448,12 +449,11 @@ if len(directClassifications) > 0 {
448449
// If you need to store the image, get the image first
449450
// and then run classifications on it. This process is slower:
450451

451-
// Get the stream from a camera
452-
camStream, err := myCam.Stream(context.Background())
453-
454-
// Get an image from the camera stream
455-
img, release, err := camStream.Next(context.Background())
456-
defer release()
452+
// Get an image from the camera decoded as an image.Image
453+
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
454+
if err != nil {
455+
logger.Fatalf("Could not decode image from camera: %v", err)
456+
}
457457

458458
// Apply the color classifier to the image from your camera (configured as "cam1")
459459
// Get the top 2 classifications with the highest confidence scores

0 commit comments

Comments
 (0)