-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
- `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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 %}} | ||
|
@@ -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 %}} | ||
|
There was a problem hiding this comment.
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