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

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 25 additions & 21 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.
- `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 try to 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)
```

To use either method, be sure to 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/components/camera#VideoSource).

{{% /tab %}}
Expand All @@ -105,11 +103,11 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/c
**Parameters:**

- `mimeType` [MimeType](https://flutter.viam.dev/viam_sdk/MimeType-class.html)? (optional)
- `extra` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>? (optional)
- `extra` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic>? (optional)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)\<[ViamImage](https://flutter.viam.dev/viam_sdk/ViamImage-class.html)\>
- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)<[ViamImage](https://flutter.viam.dev/viam_sdk/ViamImage-class.html)>

**Example:**

Expand Down Expand Up @@ -248,11 +246,11 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/c

**Parameters:**

- `extra` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>? (optional)
- `extra` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic>? (optional)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)\<[ViamImage](https://flutter.viam.dev/viam_sdk/ViamImage-class.html)\>
- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)<[ViamImage](https://flutter.viam.dev/viam_sdk/ViamImage-class.html)>

**Example:**

Expand Down Expand Up @@ -313,7 +311,7 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/c

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)\<[CameraProperties](https://flutter.viam.dev/viam_sdk/CameraProperties.html)\>
- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)<[CameraProperties](https://flutter.viam.dev/viam_sdk/CameraProperties.html)>

**Example:**

Expand Down Expand Up @@ -363,11 +361,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/

**Parameters:**

- `command` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\> (required)
- `command` [Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic> (required)

**Returns:**

- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)\<[Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)\<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic\>\>
- [Future](https://api.flutter.dev/flutter/dart-async/Future-class.html)<[Map](https://api.flutter.dev/flutter/dart-core/Map-class.html)<[String](https://api.flutter.dev/flutter/dart-core/String-class.html), dynamic>\>

**Example:**

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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The associated metadata, containing the image MIME type.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You can also try to directly decode as an `Image.Image` with the camera's `DecodeImageFromCamera` function:

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

To use either method, be sure to import `"go.viam.com/rdk/utils"` at the beginning of your file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The frame as bytes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The desired MIME type of the image. This does not guarantee output type.
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