Closed fredvol closed 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
Thanks a lot Weis, I will try this option.
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
By the way could you add in the exemples a case where you set some parameters ( number of channels , resolution) programmatically , without the GUI CameraConfig ?
also i'am using a laptop with a build-in cam , but for the record i want to use an USB webcam. I did not find a way to select the good webcam ?
I explore the cam_list = list(crappy.camera.MetaCam.classes.keys())
but there is no 2 webcam in the list.
Thanks again for your works, i really enjoy it.
ps: I'am runing on linux.
Fred,
Good to hear you were able to solve your problem !
You're right, the documentation and examples aren't always clear on how to use the camera classes. But improvements are on the way.
Currently, any argument you pass when instantiating the Camera block and that is not used by the block will be passed to the selected camera class.
For instance cam = crappy.blocks.Camera('Webcam', channels=1, width=720, height=1280, config=False)
passes arguments channels
, width
and height
to the Webcam class but not config
that is used by the Camera block.
Actually the Webcam class is generic, it allows interfacing with any USB camera.
To select the input stream, you can specify the device_num
argument when instantiating the camera (in your program : camera = customCamera(camera="Webcam", device_num=<int>, ...)
). This argument will be passed to the Webcam class.
OpenCV decides which camera corresponds to which integer, but usually the webcam is 0 and additional cameras are 1, 2, 3, etc.
Also, note that in the next release (1.5.9) a new Camera_opencv
class will allow using USB cameras with a finer control over the settings. It should be used instead of the Webcam class, which will nevertheless be kept.
Think this issue can now be closed.
Weis
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)
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