Skip to content
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

Add a Tool to acquire images from camera accessed over an HTTP route #88

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ethanjli
Copy link

@ethanjli ethanjli commented Apr 28, 2024

Changes

Adds:

  • A new HTTPCamera tool in science_jubilee/tools/HTTPCamera.py whose Python API is meant to closely follow the Camera tool's Python API but which acquires images from an HTTP route instead of using picamera

Motivation/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 the HTTPCamera tool to acquire images via HTTP from mjpg-streamer rather than acquiring them from picamera. This PR contributes my new HTTPCamera 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 for Camera being slow to acquire images could be that the get_frame method is instantiating the picamera.Picamera class each time the get_frame method is called - so the camera is doing re-initialization and warmup every time get_frame is called. My intuition is that if you just instantiate picamera.Picamera once - in the Camera class's constructor - and then reuse that instance for every get_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 the science_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:

  • Currently the URL of the image to acquire is hard-coded in the get_frame method as http://localhost:8080/?action=snapshot. Should we instead parameterize it as a keyword argument (e.g. route or url), e.g. of the get_frame method or the class constructor (and if so, which one should take the keyword argument? i.e. is it better to make a get_frame which is not exactly interchangeable with Camera's get_frame method, or is it better to make a constructor which is not exactly interchangeable with Camera's constructor)?
  • I made this tool by copy-pasting the code from the Camera tool. Is this acceptable, or would it be better to instead define this tool as a wrapper around the Camera tool, e.g. by defining HTTPCamera either as a subclass of Camera or as an object which holds an internal Camera instance but provides a Python API surface (e.g. without a video_stream method) or different in certain ways (e.g. inability to explicitly specify image resolution in any image_wells and get_well_image methods) that would make HTTPCamera non-interchangeable with Camera?
  • The PR template asks me to indicate the number of the issue which this PR resolves. Is it fine for me (@ethanjli) to open this PR without an attached issue, or should I make an issue? If the latter, should the issue be about Camera being slow to acquire images (which will be solved without this tool if/when the project migrates from picamera to picamera2, or maybe just by instantiating picamera.Picamera in the Camera tool's constructor rather than in every get_frame method), or about the lack of a way to acquire images from arbitrary picamera-incompatible cameras or simulated image sources (which might not [yet] be a real problem in need of a solution)?

PR Checklist

@ethanjli ethanjli changed the title Add a Tool to acquire images from an HTTP route Add a Tool to acquire images from camera accessed over an HTTP route Apr 28, 2024
@brendenpelkie
Copy link
Collaborator

This looks great Ethan! This is similar to the poorly named WebCamera tool, which does essentially the same thing. I like that yours doesn't get openCV involved, which will reduce install complexities for the package.

As you allude to, we have too many camera tools and there is no reason to have identical code duplicated. I opened #94 to consolidate these tools into one camera.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants