Closed abisi closed 1 year ago
Ah, somehow it's a bit hard to format code chunks in here. I'll try to fix that.
Hello
I think, the issue is caused by the videowrite. You do not know, what happens, if frames come in, but the videowriter can not write them into the video file, because Windows is busy with something else and blocking the hard disc. This happens, when Windows flushes the disc cache. The only way I personally know of getting all images is to save them into RAM while the capture runs and save them afterwards. However, this needs a lot of RAM. The IC Express software from https://www.theimagingsource.com/en-de/support/download/icexpress-1.1.0.23/ works in that way.
A word to the issue's subject: You can not know, whether a callback fails, because it is either called and executed or not, because there is no frame. The callback is not called, while a call is currently running. Therefore, you must make sure, it's runtime is below 1/framerate seconds or your trigger frequency.
I hope, this gives a little background to you.
Stefan
Hello, thank you so much for your clarifications and for your help. I tried IC Express and indeed, for our needs (i.e. 2h videos, at 200 FPS with above-mentioned image format), we need hundreds of RAM per video, which makes it an infeasible. Do you know whether it's possible, with IC Express or orther, to use batches of images in RAM to be saved? For example, 5 Gb of RAM is allocated, then saved, etc.
Axel
Hello Axel
Since the image creation is faster than saving single image, you have no chance with that.
Thus, you must stay at saving an AVI file.
I would queue the images in a list in memory. Then I would create a new thread, which saves the image from the list into the video file.
But, you simply do not know, whether vid_out.write(cv2.flip(frame,0))
was successful or not. The documentation says, it writes. It does not say anything about, it does not write or errors. Thus, this approach could work, if writing into the video file is faster, than images come in.
(I always wanted to try something similar, but I never had time for that.)
Stefan
Dear Stefan,
Thanks again for your input, this helps as I am no expert in this at all! I will try what you suggested. In particular, I will profile the callback function and check whether it's faster than the sampling period. Otherwise, I will keep looking.
Best, Axel
Axel
also safe the image buffers in a FiFo (or "queue"), so images, that are not saved to the AVI file are stored in memory for later saving.
Stefan
Hello,
Sorry for taking so long to reply to this thread... In the end, our solution was to simply trigger each frame at the desired frame rate using IC Capture, but to save the .avi file as uncompressed (in Y800).
Thank you for your time and help!
Best, Axel
Hello Axel Thank you for your feedback.
Hello,
We're trying to run 2 TIS cameras continuously with FPS 200Hz, Y800 (720x540) [Binning 2x] format for durations up to ~2h. We need to know when each frame is acquired (i.e. time of exposure) in order to sync these exposure times with other data streams. To do this, we operate cameras at > 400 Hz and perform "Software Trigger" at 200 Hz. The resulting frame is added to a cv2.VideoWriter object to save a .avi file. The issue is that we obtain more exposure times (out pulses from the camera pin) than frames in our video .avi object. As order of magnitude: a few tens of frames for minutes long videos. We're trying to match the frames to individual pulses. Here are pieces of code that do what I just said.
Callback userdata and function:
Camera initialization and software trigger:
Saving frames at desired frame rate using trigger mode:
As you can see, I have been saving time around trigger times to try to understand when/where frames can be missed. Is there a way, maybe in the callback function, to identify when exposure was done but no frame delivered? Again, we have e.g. 20050 exposure time pulses but only 20000 frames in the .avi file. We'd like to do a 1-to-1 mapping of the frames.
Let me know if you need clarifications! Thanks for your help.
Axel