-
Notifications
You must be signed in to change notification settings - Fork 124
RSDK-11831 — Make ReadImage call GetImages under the hood #5337
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?
Changes from all 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 |
---|---|---|
|
@@ -113,7 +113,7 @@ func newReadImageCollector(resource interface{}, params data.CollectorParams) (d | |
_, span := trace.StartSpan(ctx, "camera::data::collector::CaptureFunc::ReadImage") | ||
defer span.End() | ||
|
||
img, metadata, err := camera.Image(ctx, mimeStr, data.FromDMExtraMap) | ||
resImgs, resMetadata, err := camera.Images(ctx, nil, data.FromDMExtraMap) | ||
if err != nil { | ||
// A modular filter component can be created to filter the readings from a component. The error ErrNoCaptureToStore | ||
// is used in the datamanager to exclude readings from being captured and stored. | ||
|
@@ -124,14 +124,41 @@ func newReadImageCollector(resource interface{}, params data.CollectorParams) (d | |
return res, data.NewFailedToReadError(params.ComponentName, readImage.String(), err) | ||
} | ||
|
||
mimeType := data.CameraFormatToMimeType(utils.MimeTypeToFormat[metadata.MimeType]) | ||
if len(resImgs) == 0 { | ||
err = errors.New("no images returned from camera") | ||
return res, data.NewFailedToReadError(params.ComponentName, readImage.String(), err) | ||
} | ||
|
||
// Select the corresponding image based on requested mime type if provided | ||
var img NamedImage | ||
var foundMatchingMimeType bool | ||
if mimeStr != "" { | ||
for _, candidateImg := range resImgs { | ||
if candidateImg.MimeType() == mimeStr { | ||
img = candidateImg | ||
foundMatchingMimeType = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
if !foundMatchingMimeType { | ||
img = resImgs[0] | ||
} | ||
|
||
imgBytes, err := img.Bytes(ctx) | ||
if err != nil { | ||
return res, data.NewFailedToReadError(params.ComponentName, readImage.String(), err) | ||
} | ||
|
||
mimeType := data.MimeTypeStringToMimeType(img.MimeType()) | ||
ts := data.Timestamps{ | ||
TimeRequested: timeRequested, | ||
TimeReceived: time.Now(), | ||
TimeReceived: resMetadata.CapturedAt, | ||
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. Can you remind me why this change? 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. We assume 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. Cool! Thanks for explaining. |
||
} | ||
return data.NewBinaryCaptureResult(ts, []data.Binary{{ | ||
MimeType: mimeType, | ||
Payload: img, | ||
Payload: imgBytes, | ||
}}), nil | ||
}) | ||
return data.NewCollector(cFunc, params) | ||
|
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.
Nice! Since the requested mime type was already an argument before, I'm curious if this is how it worked previously, or is this new behavior?
Uh oh!
There was an error while loading. Please reload this page.
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 is new behavior since previously we would be calling
GetImage
and letting the implementer ofGetImage
handle the mime type however it wants. Now, we are returning the requested mime type iff we find it in theGetImages
response.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.
I realized this is better than always defaulting to
images[0]
as we discussed on SlackThere 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.
Makes sense! This SGTM.