jonasoh / spiro

SPIRO is a Smart Plate Imaging Robot
https://www.alyonaminina.org/spiro
BSD 2-Clause "Simplified" License
7 stars 8 forks source link

Raspberry Pi Camera Module v3 Support #43

Open WannesTacken opened 1 year ago

WannesTacken commented 1 year ago

Hello There,

I've built the SPIRO at the Laboratory of Nematology at Wageningen University & Research. Our interest is to image the Nematode infection site which requires a high definition image of the plant root. For this purpose I tried to install the raspberry pi v3 camera module but it turned out to be not compatible with the SPIRO script.

I received the following lines of error code: File "/usr/local/lib/python3.7/dist-packages/spiro/spiro.py", line 143, in main cam = initCam() File "/usr/local/lib/python3.7/dist-packages/spiro/spiro.py", line 42, in initCam cam = PiCamera() File "/usr/local/lib/python3.7/dist-packages/picamera/camera.py", line 433, in init self._init_preview() File "/usr/local/lib/python3.7/dist-packages/picamera/camera.py", line 513, in _init_preview self, self._camera.outputs[self.CAMERA_PREVIEW_PORT]) File "/usr/local/lib/python3.7/dist-packages/picamera/renderers.py", line 558, in init self.renderer.inputs[0].connect(source).enable() File "/usr/local/lib/python3.7/dist-packages/picamera/mmalobj.py", line 2212, in enable prefix="Failed to enable connection") File "/usr/local/lib/python3.7/dist-packages/picamera/exc.py", line 184, in mmal_check raise PiCameraMMALError(status, prefix)

-- Logs begin at Thu 2023-01-26 10:35:00 CET, end at Thu 2023-01-26 10:35:22 CET. --

Jan 26 10:35:05 raspberrypi systemd[529]: Started SPIRO control software. Jan 26 10:35:08 raspberrypi spiro[558]: mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC Jan 26 10:35:08 raspberrypi spiro[558]: mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x2500020 (ENOSPC) Jan 26 10:35:08 raspberrypi spiro[558]: mmal: mmal_connection_enable: output port couldn't be enabled. This is the raspberry pi error log

I updated the picamera library and legacy OS but still returned the same error. Do you have any idea what causes this and is there a workaround to make the raspberry pi camera module v3 work?

Kind regards,

Wannes Tacken Msc student Wageningen University & Research Laboratory of Nematology

jonasoh commented 1 year ago

Hi Wannes, SPIRO uses the legacy camera stack whereas the v3 camera is only supported by the new libcamera-based stack (iirc). We're planning on updating the software to work with the new stack, which should improve a lot of things including supporting the v3 camera. I can't give a good estimate as to how long this might take unfortunately. We did get our v3 camera in the mail this morning though...

If you're in a hurry, I'd recommend getting one of the recommended cameras such as the Arducam module (you'll also need a Raspberry Pi v2 camera to use it).

Sorry for the inconvenience. I'll update this issue when I know more.

Best, Jonas

WannesTacken commented 1 year ago

Hi Jonas,

Thank you for your reply, I have the arducam motorized camera installed at the moment and that will suffice for now. Looking forward to the update. Best of luck!

Regards,

Wannes

WannesTacken commented 1 year ago

@beniroquai, can you help maybe?

jonasoh commented 1 year ago

Hi, just a brief update. I haven't had time to look into this yet, but will hopefully find the time to do so this weekend. It looks like it should be an easy task coding-wise.

More problematic is the issue with dealing with updates. If switching stacks, basically every SPIRO currently running would have to be upgraded to a current Raspbian in order to get the new camera stack. And we have no clue how many SPIROs there are, or who's built one, so we can't really inform everyone why their SPIROs are starting to fail. It's likely to cause headaches. So ideally, I'd want a solution which can detect whether libcamera or Picamera is available, and use the one it finds (and which works similarly for both stacks, and supports all currently supported cameras). That may require some more thought and testing.

Anyway, will try looking into it over the weekend and will report back.

jonasoh commented 1 year ago

I now have the live view functioning in a way which should be compatible with both new and old camera stacks. Unfortunately there is what seems to be a bug in Picamera2 which is holding back progress for now (raspberrypi/picamera2/issues/554). Hopefully it will be resolved, otherwise it can probably be worked around.

I will have very limited time to work on this issue over the coming two weeks though.

beniroquai commented 1 year ago

Thanks for the update and looking into this. Did you have the chance to create a new branch with the updated codebase? Also very interested to try this out! Thanks!

On Tue, Feb 7, 2023, 09:18 Jonas Ohlsson @.***> wrote:

I now have the live view functioning in a way which should be compatible with both new and old camera stacks. Unfortunately there is what seems to be a bug in Picamera2 which is holding back progress for now ( raspberrypi/picamera2/issues/554 https://github.com/raspberrypi/picamera2/issues/554). Hopefully it will be resolved, otherwise it can probably be worked around.

I will have very limited time to work on this issue over the coming two weeks though.

— Reply to this email directly, view it on GitHub https://github.com/jonasoh/spiro/issues/43#issuecomment-1420368360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5ODJVYZGXNLFLYXD4ULWWIAL5ANCNFSM6AAAAAAUHMXYL4 . You are receiving this because you were mentioned.Message ID: @.***>

jonasoh commented 1 year ago

I haven't yet pushed the branch I am working on since it is in a quite messy state atm due to messing around with the new library... I'll try to upload it as soon as I've cleaned it up a bit.

jonasoh commented 1 year ago

BTW @WannesTacken, I am visiting Wageningen next week and never saw a real-life SPIRO outside of our lab. Do you think it would be possible to get a quick tour of your lab...? :)

beniroquai commented 1 year ago

Great! Thanks for letting me know! :-)

beniroquai commented 1 year ago

@jonasoh the setup of @WannesTacken is amazing! I have just seen it last week!

WannesTacken commented 1 year ago

@jonasoh It would be great to receive you at the laboratory of nematology! Let me know what day and time suits you.

jonasoh commented 1 year ago

@WannesTacken very cool! Do you have an email where I can reach you?

WannesTacken commented 1 year ago

@jonasoh, yes, you can email me at wannestacken@gmail.com.

jonasoh commented 1 year ago

Hi, here's an update on the progress. I now have basic functionality working, i.e., the web interface works and experiments can be run on it. I still need to fix focusing and zooming for it to be actually usable, and then I'll upload the code in a new branch for any v3 camera owners to try out.

beniroquai commented 1 year ago

Wow. Amazing. Can you even manually focus the lens?

On Tue, Feb 21, 2023, 20:01 Jonas Ohlsson @.***> wrote:

Hi, here's an update on the progress. I now have basic functionality working, i.e., the web interface works and experiments can be run on it. I still need to fix focusing and zooming for it to be actually usable, and then I'll upload the code in a new branch for any v3 camera owners to try out.

— Reply to this email directly, view it on GitHub https://github.com/jonasoh/spiro/issues/43#issuecomment-1438958848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OGCL6T2L2QEWHWGM63WYUGGVANCNFSM6AAAAAAUHMXYL4 . You are receiving this because you were mentioned.Message ID: @.***>

jonasoh commented 1 year ago

No, I don't think manual focus is possible on this camera. So for actual use, it's probably not usable without having software focusing working. It should be easy enough, hope to have it ready by Thursday.

WannesTacken commented 1 year ago

Sounds great Jonas, very excited to try it out!

jonasoh commented 1 year ago

Ok, now there's initial support for libcamera in the branch libcamera(https://github.com/jonasoh/spiro/tree/libcamera). The code is still messy and there are unsupported features (fixed white balance, no image rotation, zoom is not working), but I think it should be good to go for running an experiment and checking the image quality at least.

It's worth noting that I haven't tested it on a legacy system. The code for backwards-compatibility is there but there are probably bugs in it.

I think you can install this version using sudo pip3 install git+https://github.com/jonasoh/spiro@libcamera. Let me know if it works!