LaboratoireMecaniqueLille / crappy

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

Bug with color image recording #124

Open WeisLeDocto opened 2 months ago

WeisLeDocto commented 2 months ago

Discussed in https://github.com/LaboratoireMecaniqueLille/crappy/discussions/123

Originally posted by **joshuatbland** July 1, 2024 Hello everyone. I have a script that is collecting video from a webcam and collecting voltage values from a DAQ. For this specific project it would be helpful to collect the video in full color. I made a class based on the 'Webcam' class except it does **not** convert the image color space to gray scale in the 'get_image' function. Despite this I am still getting saved images that are in grayscale. Any advice or tips on this would be greatly appreciated. Thanks.
Originally posted by **WeisLeDocto** July 2, 2024 In addition, I just realized that there are bugs when recording color images, both with the SimpleITK and Pillow backends. With SimpleITK, the shape of the image is wrong (640x480x3 -> 3x640x480). With Pillow, the R and B channels are inverted.

As pointed out in the linked discussion, only one of the three image recording backends works as expected when recording color images. Unfortunately, the only one working (OpenCV) is also the slowest. The three backends work as expected when recording grey level images.

For the Pillow backend, it is only a matter of swapping the red and blue channels, before saving the image: https://github.com/LaboratoireMecaniqueLille/crappy/blob/e069fd4c6cf7209c56833290a24f3f4235c9684c/src/crappy/blocks/camera_processes/record.py#L234-L237

For the SimpleITK backend, it is likely that the shape of the image object needs to be modified before recording. Maybe this can be handled automatically with an argument of the conversion or record method: https://github.com/LaboratoireMecaniqueLille/crappy/blob/e069fd4c6cf7209c56833290a24f3f4235c9684c/src/crappy/blocks/camera_processes/record.py#L228-L229