Skip to content

Commit

Permalink
DOCS-3471: Update camera.md remove stream from Go camera interface (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sguequierre authored Jan 31, 2025
1 parent 0e8fef6 commit d8c1d64
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions docs/dev/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,7 @@ for d in detections:
```go
// Get image from camera stream on construction site
myCamera, err := camera.FromRobot(machine, "construction-site-cam")
camStream, err := myCamera.Stream(context.Background())
img, release, err := camStream.Next(context.Background())
defer release()
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCamera)

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

Be sure to import `"go.viam.com/rdk/utils"` at the beginning of your file.

{{% /tab %}}
{{< /tabs >}}

Expand Down
2 changes: 1 addition & 1 deletion docs/dev/reference/apis/components/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The camera API allows you to give commands to your [camera components](/operate/

The API for camera components allows you to:

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

Expand Down
12 changes: 6 additions & 6 deletions docs/operate/reference/services/vision/color_detector.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ import (
"go.viam.com/rdk/config"
"go.viam.com/rdk/services/vision"
"go.viam.com/rdk/components/camera"
"go.viam.com/rdk/utils"
)

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

// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())

// Get an image from the camera stream
img, release, err := camStream.Next(context.Background())
defer release()
// Get an image from the camera decoded as an image.Image
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
if err != nil {
logger.Fatalf("Could not decode image from camera: %v", err)
}

// Apply the color classifier to the image from your camera (configured as "cam1")
detectionsFromImage, err := myDetector.Detections(context.Background(), img, nil)
Expand Down
24 changes: 12 additions & 12 deletions docs/operate/reference/services/vision/mlmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ import (
"go.viam.com/rdk/config"
"go.viam.com/rdk/services/vision"
"go.viam.com/rdk/components/camera"
"go.viam.com/rdk/utils"
)

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

// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())

// Get an image from the camera stream
img, release, err := camStream.Next(context.Background())
defer release()
// Get an image from the camera decoded as an image.Image
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
if err != nil {
logger.Fatalf("Could not decode image from camera: %v", err)
}

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

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

// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())

// Get an image from the camera stream
img, release, err := camStream.Next(context.Background())
defer release()
// Get an image from the camera decoded as an image.Image
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCam)
if err != nil {
logger.Fatalf("Could not decode image from camera: %v", err)
}

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

0 comments on commit d8c1d64

Please sign in to comment.