-
Notifications
You must be signed in to change notification settings - Fork 122
[RSDK-10991] Create Go helpers for implementing GetImage if you have GetImages and vice versa #5055
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
base: main
Are you sure you want to change the base?
Conversation
Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!
|
… test. not just non-zero in tests
resBytes, resMetadata, err := cam.Image(ctx, mimeType, nil) | ||
if err != nil { | ||
return nil, resource.ResponseMetadata{}, fmt.Errorf("could not get image bytes from camera: %w", err) | ||
} | ||
if len(resBytes) == 0 { | ||
return nil, resource.ResponseMetadata{}, errors.New("received empty bytes from camera") | ||
} | ||
if resMetadata.MimeType != mimeType { | ||
logger.Warnf("requested mime type %s, but received %s", mimeType, resMetadata.MimeType) | ||
} |
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.
essentially the same as DecodeImageFromCamera
but added the log
This approach will force us to do decodes and encodes. I agree we need this behavior as a fallback but I'm wondering: If the method we call returns an image.Image that happens to be a LazyImage can we save ourselves some decodes and encodes? |
if len(resBytes) == 0 { | ||
return nil, resource.ResponseMetadata{}, errors.New("received empty bytes from camera") | ||
} | ||
if resMetadata.MimeType != mimeType { |
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.
should we strip lazy suffix when doing this comparison?
testImg1 := image.NewRGBA(image.Rect(0, 0, 100, 100)) | ||
testImg2 := image.NewRGBA(image.Rect(0, 0, 200, 200)) | ||
|
||
testCam := inject.NewCamera("test_cam") |
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.
testCam := inject.NewCamera("test_cam") | |
rgbaCam := inject.NewCamera("rgba_cam") |
t.Run("request empty mime type", func(t *testing.T) { | ||
_, _, err := camera.GetImageFromGetImages(context.Background(), nil, "", testCam) | ||
test.That(t, err, test.ShouldBeError, errors.New("could not encode image: do not know how to encode \"\"")) | ||
}) |
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.
this should default to jpeg
RSDK-10991
Create Go helpers for implementing GetImage if you have GetImages and vice versa