Labsmore / pyuscope

Python machine vision platform
BSD 2-Clause "Simplified" License
76 stars 16 forks source link

Add support for Raspberry Pi Cameras via picam2 #362

Open philpem opened 7 months ago

philpem commented 7 months ago

This ticket is a request for comments and collection of the discussions I've had on the Discord about this little project of mine.

I've been building an XYZ scanning microscope, using a Raspberry Pi 4 and High Quality Camera mated to an Olympus BHM (BH2-era) using an Olympus C-mount adapter on the trinocular port. Motion control is with a RAMPS1.4 board running GRBL and some motors I liberated from a broken 3D printer.

My initial plan was to modify the Pyuscope gstreamer backend to support the Libcamera source, but this had some issues:

I had a look at the Libcamera Bugzilla and it seems that the bugs above are known; the corruption issue may be this buffer alignment one, which has seen no activity since it was reported in November 2022. In regards to properties, the GST camera provider only supports the Autofocus property. Nothing else is passed along to the camera.

I have no experience writing Gstreamer sources, so instead I opted to modify Pyuscope to add support for the Raspberry Pi project's "picam2" library. This turned out to be about a day's work to get something rough working: https://github.com/philpem/pyuscope-rpicam/tree/philpem_olympusbh_raspi

I'm open to comments on what I've done on this branch - I'm sure there are better ways to do some of the things I've done. It would be nice to get things into a state where they could be merged in -- though that's not a red line. If picam2 support isn't inline with the project goals then I'm OK with maintaining my fork on an 'it works for me' basis.

I've tested Autofocus, Snapshot and Panorama Capture and all seems to work fine. Support for camera parameters/settings are missing - so everything's set to the defaults. I'm planning to add support for White Balance auto/mode/lock and Exposure auto/lock as a minimum, but will likely add some of the other Pi Camera features too.

JohnDMcMaster commented 7 months ago

Hi philpem! Thanks for your info. Let me start by adding some info on my Supercon experiment with Mithro

Notes:

philpem commented 5 months ago

I've been working on this some more, and have a pretty usable version of this on my branch.

Imaging and panorama capture work as intended (or at least intuitively enough that I can't tell if there's breakage). Imaging controls also work, these are fairly simplistic. Not having support for floating-point values in the UI makes things a bit hairier than I'd prefer, but the multiplier factor is an OK workaround.

Development of this has uncovered a couple of other minor bugs in Pyuscope, for which I've opened separate issues.

JohnDMcMaster commented 5 months ago

Thanks for filing the issues! Trying to triage and take a look over things. The biggest issue I need to figure out is what can be merged that isn't a maintenance burden to keep the other stuff moving. In my ideal world for example the video sources become more plugin like than they are now so changes can be better isolated