LaboratoireMecaniqueLille / crappy

Command and Real-time Acquisition Parallelized in Python
https://crappy.readthedocs.io/en/stable/
GNU General Public License v2.0
81 stars 16 forks source link

sending image frame to custom block #10

Closed fredvol closed 2 years ago

fredvol commented 2 years ago

Hello ,

First a big thanks to you work ! it s amazing. I'am using crappy to monitor a small wind tunnel to help us developing paraglider.

After few days of trying i'am struggling to save image from webcam only when a button of a GUI is on ( button =State) state_on

I had several tactic:

My last try is to create a custom block save_cam_blck with :

as soon as i link camera to save_cam_blck i got : WARNING : Timeout error in pipe send! Link name: link and the camera loop is super slow >1 fps.

what i'am missing ?

i did a simpler version of my code: https://gist.github.com/fredvol/fa817dc8ee193f3cda9be672a848e2f8 Many thanks for your help.

Fred

WeisLeDocto commented 2 years ago

Hello Fred,

Good to see that we start to have users outside of our lab !

Note that I'm currently working on improving most of the the camera-related blocks. They haven't been updated in a while and there is much to do. So expect a few improvements coming soon !

Regarding your specific issue, the easiest and most efficient way to save images in Crappy is to use the save_folder argument of the Camera block. This way the images don't have to be transferred through a link before being saved (I still have to parallelize the saving and the acquisition, it is not optimal now). As you can see here the images are saved only if save_folder is given. Using a custom block it is possible to modify the value of this attribute during a test, which is I think the easiest way to achieve what you want to do.

As the Camera block lives in a separate process as soon as the test starts, this is not straightforward though. The strategy I would suggest is to use a modified version of Camera taking a multiprocessing.connection.Connection as an argument, polling the connection at each loop and changing the save_folder value accordingly if needed. The other connection would be held by the GUI, that would send the value of save_folder to set. Note that this is roughly equivalent to creating a crappy.link between your GUI and your custom Camera block, but it is in my opinion a lighter and more flexible solution.

Now regarding the problem of the link being down, this is caused by images accumulating in a link until it is full. The last added image is truncated as it doesn't fit entirely in the link, and once it is read by a downstream block the link is permanently down. On my machine I can get your code running with the image in grey level, but not with larger images in RGB. Maybe I'll think of a workaround once I start refactoring the Camera and Displayer code.

Tell me if you're successful with the proposed solution. And out of curiosity, are you running the code on Linux or Windows ?

Weis

fredvol commented 2 years ago

Thanks a lot Weis, I will try this option.

fredvol commented 2 years ago

Hello,

I 'managed to make it work ! Thanks a lot for your help.

I put it as a gist in case it can help others: https://gist.github.com/fredvol/8981c93d6e35de3a2ca42f454841894d

Thanks again for your works, i really enjoy it.

ps: I'am runing on linux.

WeisLeDocto commented 2 years ago

Fred,

Good to hear you were able to solve your problem !

Think this issue can now be closed.

Weis