Photometrics / PyVCAM

Python3.X wrapper for Photometrics and QImaging PVCAM based cameras
MIT License
36 stars 17 forks source link

Buffer of frames and python wrapper #18

Closed kasasxav closed 3 years ago

kasasxav commented 3 years ago

Hey !

I am trying to implement PyVCAM in my project and I have two issues I wanted to discuss:

Probably this is already possible somehow but I haven't managed to find a solution.

stevebellinger commented 3 years ago

Hi there.

  1. For the poll_frame stuck problem. My first suggestion is to only call start_live when you know the external trigger source is active. If that's not possible, I can help you modify the wrapper to include a timeout on the poll_frame function so that the function never hangs.
  2. I'm not entirely sure what you are looking for with the unread frames request. Can you elaborate on your use case? How many frames do you want to buffer and how often? In live mode, PVCAM buffers up to 16 frames, but PyVCAM only gives you access to the latest frame. This behavior can be modified. Alternatively, perhaps you can switch to sequence mode? Sequence mode can buffer more than 16 frames and can give you access to all buffered frames.
kasasxav commented 3 years ago

Thank you for the quick reply :)

  1. I tried a bit in that direction already but the problem is that I don't always know when it stops, so then it's hanging in the end and I can't terminate it. The problem is that the camera is synchronized with other devices so it's not always trivial to know when it will stop acquiring images since it also depends on how many there are in the buffer. I wouldn't mind changing the wrapper if you give me some guidelines, that would be very nice!

  2. So when I take a scan it can be around 800 frames, and I have a thread that saves them into memory continuously. Usually, with my other camera, I was calling a function that got the ones that I hadn't read yet by the time of execution since I might call the function to grab the frames slower than the camera grabs them. So I'm not sure how to proceed in this case. Do you think sequence mode is compatible in this case? I guess the issue is that sometimes I don't know how many frames there will be but I could run sequence mode in a cycle, I guess.

stevebellinger commented 3 years ago

No problem.

  1. I can do the change, but not until tomorrow at the earliest. If you want to give it a shot, take a look at pvcmodule.cpp:767. You want to comment out the whole ALLOWTHREADS section and throw an exception (return NULL) if camInstance.newData is false.
  2. Sequence mode is not going to be suitable for this many frames. It is possible to alter PyVCAM to allow access to the full live mode circular buffer and even increase the depth of the buffer. But before we go that route, do you have a notion for how the deep the buffer needs to be? Is it possible to tune your application so that poll_frame always gets called faster than the frame rate?
kasasxav commented 3 years ago
  1. Thanks ! I will try a bit as well, thank you for the direction.
  2. I think if we fix 1., probably by being able to read the 16 frames buffer it might be good enough, I should check. The thread goes quite fast, it's just that if the exposure is 10ms then it's easy to lose frames if I can't access the full circular buffer.
stevebellinger commented 3 years ago

Sounds good. If you don't mind, please post your work in a branch so that I can follow along and help.

kasasxav commented 3 years ago

Then now the only thing would be to have a function get_frames to return all frames in the buffer, and we already have get_latest_frame (poll_latest_frame) for getting the last one, which I use for display (which I took from the branch poll_latest_frame)

kasasxav commented 3 years ago

Let me kow about this second one, I haven't done pr yet. So far I think I managed to not reset the queue but still doesn't return all frames available.