From d8c1d64f871744af3ba07ebf8c7529c2df9a552d Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Fri, 31 Jan 2025 17:40:41 -0500 Subject: [PATCH] DOCS-3471: Update camera.md remove stream from Go camera interface (#3942) --- docs/dev/_index.md | 6 ++--- docs/dev/reference/apis/components/camera.md | 2 +- .../services/vision/color_detector.md | 12 +++++----- .../reference/services/vision/mlmodel.md | 24 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/dev/_index.md b/docs/dev/_index.md index 9482f107aa..4a9639d00c 100644 --- a/docs/dev/_index.md +++ b/docs/dev/_index.md @@ -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") @@ -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 >}} diff --git a/docs/dev/reference/apis/components/camera.md b/docs/dev/reference/apis/components/camera.md index 1156efd89d..129c3dd27b 100644 --- a/docs/dev/reference/apis/components/camera.md +++ b/docs/dev/reference/apis/components/camera.md @@ -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. diff --git a/docs/operate/reference/services/vision/color_detector.md b/docs/operate/reference/services/vision/color_detector.md index 595ad7603b..222722413a 100644 --- a/docs/operate/reference/services/vision/color_detector.md +++ b/docs/operate/reference/services/vision/color_detector.md @@ -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 @@ -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) diff --git a/docs/operate/reference/services/vision/mlmodel.md b/docs/operate/reference/services/vision/mlmodel.md index fa307e857c..59d4667f85 100644 --- a/docs/operate/reference/services/vision/mlmodel.md +++ b/docs/operate/reference/services/vision/mlmodel.md @@ -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" @@ -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) @@ -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" @@ -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