From 003c3792d200670b67e3fb1685fdc22724f4c416 Mon Sep 17 00:00:00 2001 From: hexbabe Date: Thu, 14 Nov 2024 16:52:09 -0500 Subject: [PATCH] GoImageFromCamera -> DecodeImageFromCamera --- components/camera/camera.go | 6 +++--- components/camera/camera_test.go | 4 ++-- components/camera/client.go | 2 +- components/camera/client_test.go | 10 +++++----- components/camera/fake/camera_test.go | 2 +- components/camera/fake/image_file_test.go | 2 +- components/camera/transformpipeline/mods.go | 4 ++-- robot/client/client_test.go | 2 +- robot/impl/local_robot_test.go | 3 ++- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/components/camera/camera.go b/components/camera/camera.go index 1c6732f45a9..e010f2f5a22 100644 --- a/components/camera/camera.go +++ b/components/camera/camera.go @@ -96,7 +96,7 @@ type Camera interface { // Or try to directly decode into an image.Image: // // myCamera, err := camera.FromRobot(machine, "my_camera") -// img, err = camera.ImageFromVideoSource(context.Background(), utils.MimeTypeJPEG, nil, myCamera) +// img, err = camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeJPEG, nil, myCamera) // // Images example: // @@ -159,8 +159,8 @@ func ReadImage(ctx context.Context, src gostream.VideoSource) (image.Image, func return gostream.ReadImage(ctx, src) } -// GoImageFromCamera retrieves image bytes from a camera resource and serializes it as an image.Image. -func GoImageFromCamera(ctx context.Context, mimeType string, extra map[string]interface{}, cam Camera) (image.Image, error) { +// DecodeImageFromCamera retrieves image bytes from a camera resource and serializes it as an image.Image. +func DecodeImageFromCamera(ctx context.Context, mimeType string, extra map[string]interface{}, cam Camera) (image.Image, error) { resBytes, resMetadata, err := cam.Image(ctx, mimeType, extra) if err != nil { return nil, fmt.Errorf("could not get image bytes from camera: %w", err) diff --git a/components/camera/camera_test.go b/components/camera/camera_test.go index 23a6f44ab0d..4cfd9d99baa 100644 --- a/components/camera/camera_test.go +++ b/components/camera/camera_test.go @@ -185,7 +185,7 @@ func TestCameraWithNoProjector(t *testing.T) { _, got := pc.At(0, 0, 0) test.That(t, got, test.ShouldBeTrue) - img, err := camera.GoImageFromCamera(context.Background(), rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, noProj2) + img, err := camera.DecodeImageFromCamera(context.Background(), rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, noProj2) test.That(t, err, test.ShouldBeNil) test.That(t, img.Bounds().Dx(), test.ShouldEqual, 1280) @@ -234,7 +234,7 @@ func TestCameraWithProjector(t *testing.T) { _, got := pc.At(0, 0, 0) test.That(t, got, test.ShouldBeTrue) - img, err := camera.GoImageFromCamera(context.Background(), rutils.MimeTypePNG, nil, cam2) + img, err := camera.DecodeImageFromCamera(context.Background(), rutils.MimeTypePNG, nil, cam2) test.That(t, err, test.ShouldBeNil) test.That(t, err, test.ShouldBeNil) diff --git a/components/camera/client.go b/components/camera/client.go index 0feda87fdb8..e717e9868d3 100644 --- a/components/camera/client.go +++ b/components/camera/client.go @@ -146,7 +146,7 @@ func (c *client) Stream( return } - img, err := GoImageFromCamera(streamCtx, mimeTypeFromCtx, nil, c) + img, err := DecodeImageFromCamera(streamCtx, mimeTypeFromCtx, nil, c) if err != nil { for _, handler := range errHandlers { handler(streamCtx, err) diff --git a/components/camera/client_test.go b/components/camera/client_test.go index 031a12c1ca2..0acceee499d 100644 --- a/components/camera/client_test.go +++ b/components/camera/client_test.go @@ -178,12 +178,12 @@ func TestClient(t *testing.T) { test.That(t, err, test.ShouldBeNil) camera1Client, err := camera.NewClientFromConn(context.Background(), conn, "", camera.Named(testCameraName), logger) test.That(t, err, test.ShouldBeNil) - frame, err := camera.GoImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, nil, camera1Client) + frame, err := camera.DecodeImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, nil, camera1Client) test.That(t, err, test.ShouldBeNil) compVal, _, err := rimage.CompareImages(img, frame) test.That(t, err, test.ShouldBeNil) test.That(t, compVal, test.ShouldEqual, 0) // exact copy, no color conversion - _, err = camera.GoImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, map[string]interface{}{"empty": true}, camera1Client) + _, err = camera.DecodeImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, map[string]interface{}{"empty": true}, camera1Client) test.That(t, err, test.ShouldNotBeNil) test.That(t, err.Error(), test.ShouldContainSubstring, "received empty bytes from Image method") @@ -228,7 +228,7 @@ func TestClient(t *testing.T) { test.That(t, err, test.ShouldBeNil) ctx := context.Background() - frame, err := camera.GoImageFromCamera(ctx, rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, client) + frame, err := camera.DecodeImageFromCamera(ctx, rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, client) test.That(t, err, test.ShouldBeNil) dm, err := rimage.ConvertImageToDepthMap(context.Background(), frame) test.That(t, err, test.ShouldBeNil) @@ -469,7 +469,7 @@ func TestClientLazyImage(t *testing.T) { test.That(t, err, test.ShouldBeNil) ctx := context.Background() - frame, err := camera.GoImageFromCamera(ctx, rutils.MimeTypePNG, nil, camera1Client) + frame, err := camera.DecodeImageFromCamera(ctx, rutils.MimeTypePNG, nil, camera1Client) test.That(t, err, test.ShouldBeNil) // Should always lazily decode test.That(t, frame, test.ShouldHaveSameTypeAs, &rimage.LazyEncodedImage{}) @@ -477,7 +477,7 @@ func TestClientLazyImage(t *testing.T) { test.That(t, frameLazy.RawData(), test.ShouldResemble, imgBuf.Bytes()) ctx = context.Background() - frame, err = camera.GoImageFromCamera(ctx, rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, camera1Client) + frame, err = camera.DecodeImageFromCamera(ctx, rutils.WithLazyMIMEType(rutils.MimeTypePNG), nil, camera1Client) test.That(t, err, test.ShouldBeNil) test.That(t, frame, test.ShouldHaveSameTypeAs, &rimage.LazyEncodedImage{}) frameLazy = frame.(*rimage.LazyEncodedImage) diff --git a/components/camera/fake/camera_test.go b/components/camera/fake/camera_test.go index 7760e2fcb53..4d14c1ca7ba 100644 --- a/components/camera/fake/camera_test.go +++ b/components/camera/fake/camera_test.go @@ -94,7 +94,7 @@ func TestRTPPassthrough(t *testing.T) { cam, err := NewCamera(context.Background(), nil, cfg, logger) test.That(t, err, test.ShouldBeNil) - img, err := camera.GoImageFromCamera(context.Background(), utils.MimeTypeRawRGBA, nil, cam) + img, err := camera.DecodeImageFromCamera(context.Background(), utils.MimeTypeRawRGBA, nil, cam) test.That(t, err, test.ShouldBeNil) // GetImage returns the world jpeg test.That(t, img.Bounds(), test.ShouldResemble, image.Rectangle{Max: image.Point{X: 480, Y: 270}}) diff --git a/components/camera/fake/image_file_test.go b/components/camera/fake/image_file_test.go index 71835d0db01..86fbe1ff325 100644 --- a/components/camera/fake/image_file_test.go +++ b/components/camera/fake/image_file_test.go @@ -102,7 +102,7 @@ func TestColorOddResolution(t *testing.T) { cam, err := newCamera(ctx, resource.Name{API: camera.API}, cfg, logger) test.That(t, err, test.ShouldBeNil) - strmImg, err := camera.GoImageFromCamera(ctx, utils.MimeTypeRawRGBA, nil, cam) + strmImg, err := camera.DecodeImageFromCamera(ctx, utils.MimeTypeRawRGBA, nil, cam) test.That(t, err, test.ShouldBeNil) expectedBounds := image.Rect(0, 0, img.Bounds().Dx()-1, img.Bounds().Dy()-1) diff --git a/components/camera/transformpipeline/mods.go b/components/camera/transformpipeline/mods.go index 0331f300399..e644438939a 100644 --- a/components/camera/transformpipeline/mods.go +++ b/components/camera/transformpipeline/mods.go @@ -95,7 +95,7 @@ type resizeConfig struct { } type resizeSource struct { - src camera.VideoSource + src camera.Camera stream camera.ImageType height int width int @@ -103,7 +103,7 @@ type resizeSource struct { // newResizeTransform creates a new resize transform. func newResizeTransform( - ctx context.Context, source camera.VideoSource, stream camera.ImageType, am utils.AttributeMap, + ctx context.Context, source camera.Camera, stream camera.ImageType, am utils.AttributeMap, ) (camera.VideoSource, camera.ImageType, error) { conf, err := resource.TransformAttributeMap[*resizeConfig](am) if err != nil { diff --git a/robot/client/client_test.go b/robot/client/client_test.go index 86f1d4c8e08..27b70d954c9 100644 --- a/robot/client/client_test.go +++ b/robot/client/client_test.go @@ -584,7 +584,7 @@ func TestStatusClient(t *testing.T) { camera1, err = camera.FromRobot(client, "camera1") test.That(t, err, test.ShouldBeNil) - frame, err := camera.GoImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, nil, camera1) + frame, err := camera.DecodeImageFromCamera(context.Background(), rutils.MimeTypeRawRGBA, nil, camera1) test.That(t, err, test.ShouldBeNil) compVal, _, err := rimage.CompareImages(img, frame) test.That(t, err, test.ShouldBeNil) diff --git a/robot/impl/local_robot_test.go b/robot/impl/local_robot_test.go index 9f942b2171c..0a03ee0ea29 100644 --- a/robot/impl/local_robot_test.go +++ b/robot/impl/local_robot_test.go @@ -20,6 +20,7 @@ import ( "github.com/golang/geo/r3" "go.mongodb.org/mongo-driver/bson/primitive" "go.uber.org/zap" + // registers all components. commonpb "go.viam.com/api/common/v1" armpb "go.viam.com/api/component/arm/v1" @@ -93,7 +94,7 @@ func TestConfig1(t *testing.T) { c1, err := camera.FromRobot(r, "c1") test.That(t, err, test.ShouldBeNil) test.That(t, c1.Name(), test.ShouldResemble, camera.Named("c1")) - pic, err := camera.GoImageFromCamera(context.Background(), rutils.MimeTypeJPEG, nil, c1) + pic, err := camera.DecodeImageFromCamera(context.Background(), rutils.MimeTypeJPEG, nil, c1) test.That(t, err, test.ShouldBeNil) bounds := pic.Bounds()