Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-3196: Update Camera interface for Go Image function and remove Stream/Next #3854

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sdk_protos_map.csv
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ board,GetResourceName,No,get_resource_name,,getResourceName
board,Close,No,close,Close,

## Camera
camera,GetImage,,get_image,Stream,image
camera,GetImage,,get_image,Image,image
camera,GetImages,,get_images,Images,
camera,RenderFrame,,,,
camera,GetPointCloud,,get_point_cloud,NextPointCloud,pointCloud
Expand Down
32 changes: 18 additions & 14 deletions static/include/components/apis/generated/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,34 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
{{% /tab %}}
{{% tab name="Go" %}}

{{% alert title="Info" color="info" %}}

Unlike most Viam [component APIs](/dev/reference/apis/#component-apis), the methods of the Go camera client do not map exactly to the names of the other SDK's camera methods.
To get an image in the Go SDK, you first need to construct a `Stream` and then you can get the next image from that stream.

{{% /alert %}}

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
- `errHandlers` [(...gostream.ErrorHandler)](https://pkg.go.dev/go.viam.com/rdk/gostream#ErrorHandler): A handler for errors allowing for logic based on consecutively retrieved errors.
- `mimeType` [(string)](https://pkg.go.dev/builtin#string): The desired mime type of the image. This does not guarantee output type.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit/oopt] if you care to, update "MIME" upstream to be capitalized, here and elsewhere

- `extra` [(map[string]interface{})](https://go.dev/blog/maps): Extra options to pass to the underlying RPC call.

**Returns:**

- [(gostream.VideoStream)](https://pkg.go.dev/go.viam.com/rdk/gostream#VideoStream): A `VideoStream` that streams video until closed.
- [([]byte)](https://pkg.go.dev/builtin#byte): The frame as bytes.
- [(ImageMetadata)](https://pkg.go.dev/go.viam.com/rdk/components/camera#ImageMetadata): The associated metadata, containing the image mime type.
- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

**Example:**

```go {class="line-numbers linkable-line-numbers"}
myCamera, err := camera.FromRobot(machine, "my_camera")
imageBytes, mimeType, err := myCamera.Image(context.Background(), utils.MimeTypeJPEG, nil)
```

// gets the stream from a camera
stream, err := myCamera.Stream(context.Background())
You can also directly decode as an `Image.Image` with the camera's `DecodeImageFromCamera` function:

// gets an image from the camera stream
img, release, err := stream.Next(context.Background())
defer release()
```go {class="line-numbers linkable-line-numbers"}
myCamera, err := camera.FromRobot(machine, "my_camera")
img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCamera)
```

If you use this method, be sure to import `"go.viam.com/rdk/utils"` at the beginning of your file.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this tripped me up when testing-- imported wrong utils-- so wanted to specify

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Does this need to be added to an override in order to stay here in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added!


For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/components/camera#VideoSource).

{{% /tab %}}
Expand Down Expand Up @@ -449,6 +447,12 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

- [ResourceName](https://flutter.viam.dev/viam_sdk/ResourceName-class.html)

**Example:**

```dart {class="line-numbers linkable-line-numbers"}
final myCameraResourceName = myCamera.getResourceName("my_camera");
```

For more information, see the [Flutter SDK Docs](https://flutter.viam.dev/viam_sdk/Camera/getResourceName.html).

{{% /tab %}}
Expand Down
24 changes: 10 additions & 14 deletions static/include/services/apis/generated/vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@ if err != nil {
logger.Error(err)
return
}
// 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)

myDetectorService, err := vision.FromRobot(machine, "my_detector")
if err != nil {
Expand All @@ -168,6 +166,8 @@ if len(detections) > 0 {
}
```

Import `"go.viam.com/rdk/utils"` at the beginning of your file.

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision#Service).

{{% /tab %}}
Expand Down Expand Up @@ -341,15 +341,9 @@ if err != nil {
logger.Error(err)
return
}
// Get the stream from a camera
camStream, err := myCam.Stream(context.Background())
if err!=nil {
logger.Error(err)
return
}
// 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)

myClassifierService, err := vision.FromRobot(machine, "my_classifier")
if err != nil {
Expand All @@ -366,6 +360,8 @@ if len(classifications) > 0 {
}
```

Import `"go.viam.com/rdk/utils"` at the beginning of your file.

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision#Service).

{{% /tab %}}
Expand Down
Loading