Add a Tool to acquire images from camera accessed over an HTTP route #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Adds:
HTTPCamera
tool inscience_jubilee/tools/HTTPCamera.py
whose Python API is meant to closely follow theCamera
tool's Python API but which acquires images from an HTTP route instead of using picameraMotivation/Context
In the POSE Workshop on 2024-04-27, a mini-project to use the Jubilee as an object scanner found that image acquisition was really slow due to how
picamera
works. As a quick-and-dirty workaround, I deployed https://github.com/jacksonliam/mjpg-streamer onto the Jubilee's Raspberry Pi computer and added theHTTPCamera
tool to acquire images via HTTP from mjpg-streamer rather than acquiring them frompicamera
. This PR contributes my newHTTPCamera
tool, since it sounded like there might be some interest in the tool itself, and since I volunteered to be a "guinea pig" for the process of submitting new tools as an external contributor which could lead to new docs or templates to help people share their tools.Alternatives
Having inspected the
Camera
source code, I think a potential cause forCamera
being slow to acquire images could be that theget_frame
method is instantiating thepicamera.Picamera
class each time theget_frame
method is called - so the camera is doing re-initialization and warmup every timeget_frame
is called. My intuition is that if you just instantiatepicamera.Picamera
once - in theCamera
class's constructor - and then reuse that instance for everyget_frame
method call, you may be able to acquire images much more quickly. I can try to make this change in a new PR, but (as mentioned below in the PR checklist) I'm not sure if I'll be able to test it out in thescience_jubilee
repo. If it works, that would be a more direct solution to the issue of slow image acquisitions.Unresolved Questions
Because this PR was made from hackathon-quality code (i.e. it took some shortcuts to make things work quickly), I don't think it's ready to change the status of this PR from "draft" to "ready for review" until we address some questions:
get_frame
method ashttp://localhost:8080/?action=snapshot
. Should we instead parameterize it as a keyword argument (e.g.route
orurl
), e.g. of theget_frame
method or the class constructor (and if so, which one should take the keyword argument? i.e. is it better to make aget_frame
which is not exactly interchangeable withCamera
'sget_frame
method, or is it better to make a constructor which is not exactly interchangeable withCamera
's constructor)?Camera
tool. Is this acceptable, or would it be better to instead define this tool as a wrapper around theCamera
tool, e.g. by definingHTTPCamera
either as a subclass ofCamera
or as an object which holds an internalCamera
instance but provides a Python API surface (e.g. without avideo_stream
method) or different in certain ways (e.g. inability to explicitly specify image resolution in anyimage_wells
andget_well_image
methods) that would makeHTTPCamera
non-interchangeable withCamera
?Camera
being slow to acquire images (which will be solved without this tool if/when the project migrates frompicamera
topicamera2
, or maybe just by instantiatingpicamera.Picamera
in theCamera
tool's constructor rather than in everyget_frame
method), or about the lack of a way to acquire images from arbitrarypicamera
-incompatible cameras or simulated image sources (which might not [yet] be a real problem in need of a solution)?PR Checklist
Camera
class even though I don't have access to Jubilee hardware.