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/robot/client/client_test.go b/robot/client/client_test.go index 6a54c4b60c4..27b70d954c9 100644 --- a/robot/client/client_test.go +++ b/robot/client/client_test.go @@ -332,9 +332,7 @@ func TestStatusClient(t *testing.T) { test.That(t, png.Encode(&imgBuf, img), test.ShouldBeNil) injectCamera.ImageFunc = func(ctx context.Context, mimeType string, extra map[string]interface{}) ([]byte, camera.ImageMetadata, error) { - resBytes, err := rimage.EncodeImage(ctx, img, mimeType) - test.That(t, err, test.ShouldBeNil) - return resBytes, camera.ImageMetadata{MimeType: mimeType}, nil + return imgBuf.Bytes(), camera.ImageMetadata{MimeType: rutils.MimeTypePNG}, nil } injectInputDev := &inject.InputController{} @@ -510,7 +508,7 @@ func TestStatusClient(t *testing.T) { test.That(t, err, test.ShouldNotBeNil) test.That(t, err.Error(), test.ShouldContainSubstring, "not found") test.That(t, imgBytes, test.ShouldBeNil) - test.That(t, metadata, test.ShouldEqual, camera.ImageMetadata{}) + test.That(t, metadata, test.ShouldResemble, camera.ImageMetadata{}) gripper1, err := gripper.FromRobot(client, "gripper1") test.That(t, err, test.ShouldBeNil) @@ -586,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()