[RSDK-11780, RSDK-11704] CaptureAllFromCamera in vision/service.py still expects Image.mime_type to be Format type, not str#993
Conversation
|
Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!
|
njooma
left a comment
There was a problem hiding this comment.
I don't think we need to use .value everywhere. According to the docs, an enum that subclasses from str should behave just like a string
src/viam/components/camera/camera.py
Outdated
| The extra parameter can be used to pass additional options to the camera resource. The filter_source_names parameter can be used to filter | ||
| only the images from the specified source names. When unspecified, all images are returned. | ||
|
|
There was a problem hiding this comment.
Add the filter_source_names arg like we do in the get_image docstring. no need to add extra to this list of args
src/viam/components/camera/client.py
Outdated
| else: | ||
| # TODO(RSDK-11728): remove this once we deleted the format field | ||
| mime_type = str(CameraMimeType.from_proto(img_data.format)) | ||
| mime_type = CameraMimeType.from_proto(img_data.format).value |
There was a problem hiding this comment.
Does this need to happen? CameraMimeType is a string, and should be accepted wherever strs are accepted
There was a problem hiding this comment.
Sorry this PR wasn't really ready to review yet. This repo seems to auto-request reviews. I was just doing this to see if more tests would fail as an experiment. I've changed them back
src/viam/media/utils/pil/__init__.py
Outdated
| Args: | ||
| image (Image.Image): The image to convert. | ||
| mime_type (CameraMimeType): The mime type to convert the image to. | ||
| mime_type (str): The mime type to convert the image to. Must be one of the `CameraMimeType` enum string literals. |
There was a problem hiding this comment.
If this must be one of the enum properties, why not keep this as CameraMimeType?
src/viam/media/video.py
Outdated
| def __str__(self) -> str: | ||
| return self.value | ||
|
|
There was a problem hiding this comment.
Really only helpful for printing
769b30b to
f8c39c7
Compare
be404a7 to
162aa7e
Compare
| # Make sure at runtime the mime_type string is actually a CameraMimeType | ||
| if not isinstance(mime_type, CameraMimeType): | ||
| raise ValueError(f"Unsupported mimetype str: {mime_type}") | ||
|
|
There was a problem hiding this comment.
Were you running into issues here?
There was a problem hiding this comment.
No, but the user can pass str in runtime regardless of the hint, so I figured it'd be good to give a more explicit error when that happens.
src/viam/services/vision/service.py
Outdated
| request = await stream.recv_message() | ||
| assert request is not None | ||
| vision = self.get_resource(request.name) | ||
| vision: Vision = self.get_resource(request.name) |
There was a problem hiding this comment.
What you can also do to fix this type issue is on line 29, update the class inheritance to be VisionRPCService(UnimplementedVisionServiceBase, ResourceRPCServiceBase[Vision])
There was a problem hiding this comment.
Nice I like that. Done and removed inline hint
bhaney
left a comment
There was a problem hiding this comment.
mostly questions about things for this PR
| VISION_IMAGE = ViamImage(bytes([0, 100]), CameraMimeType.JPEG) | ||
| # Use string value of CameraMimeType because ViamImage accepts a string mime type in the worst case | ||
| # and it may not have the expected CameraMimeType methods defined on it. | ||
| VISION_IMAGE = ViamImage(bytes([0, 100]), CameraMimeType.JPEG.value) |
There was a problem hiding this comment.
Still curious why we want to use a second VISION_IMAGE here when we already have an IMAGE variable (used in other tests) that could be used in the same way.
There was a problem hiding this comment.
I believe it's to make writing the mock easier? @njooma ?
There was a problem hiding this comment.
I still don't have an answer to this question, so won't approve until then
…sts fail due to them
CLOSING since #995 fixes the issue
Fix bug by handling mime type type conversion in vision service server and client
Manual Tests
Test with python vision service
Created a fake vision model that serves only
capture_all_from_cameraand returns a blank white JPEG https://github.com/hexbabe/heart-beat-module/blob/6e167e9119c0d096bf0fb2cdef50cdcfdb5c3f4a/src/fake_vision.py#L59-L77Uninstalled the pypi version of
viam_sdkand manually installed my current feature branch built local wheel of the SDK to the virtual environment of the moduleUsed a Python client to call
capture_all_from_cameraOutput
Also opened the image and confirmed it was a blank white jpeg
Regression test with
oak-dRan the same test as from #982 (comment) and verified no regression for GetImages server and client.