0

I am using an GigEPRO camera and which has a capability of 60fps or more based on image size. Therefore for 60fps indicates 1 frame/16ms. But the videowriter function itself consumes 2-4ms. So I have decided to store the images in vector<Mat> and create a child_thread that is responsible for writing the images to video using writer function from OpenCV by accessing the images for the vector and erase the image stored.

I have few queries for this implementation. Can I use the vector<Mat> to store images or should I create a Queue.? How can I synchronize the child_thread with main thread?

I am new to multi-threading programming therefore looking for some inputs

Reddy2810
  • 312
  • 2
  • 17
  • your math is wrong. 60fps => 1000ms / 60 frames = 1 frame every 16.666... milliseconds. Anyway de-coupling acquisition thread and write/recorder thread with a frames queue in-betweeen is a good sane practice ;-) – roalz Jan 10 '17 at 09:55
  • oh. ya thank you. but I am not sure of how to implement in coding. In general I want to increase the fps to 100 fps later by decreasing the image size. – Reddy2810 Jan 10 '17 at 10:08
  • See [this answer](http://stackoverflow.com/a/37146523/3962537) for inspiration. – Dan Mašek Jan 10 '17 at 12:03
  • @Dan Masek, I saw your code and what the max possible fps? Since i need around 130fps image resolution of 1200*700 with single channel image for a duration of 20 sec. – Reddy2810 Jan 18 '17 at 16:18

2 Answers2

1

De-coupling acquisition thread and writer/recorder thread with a frames queue in-betweeen is a good sane practice.

At some point the incoming stream may be faster than the output write operation (expecially if you are writing to slow devices such as disks).
To prevent an ever growing queue (that would eat up all the available memory on the PC), you may consider a queue with maximum items limit.

An option is to write your own queue-like class that:
1. uses internally a suitable container (i.e. std::queue<> or std::deque<>, because std::queue by defaule uses a std::deque already)
2. exposes only the functions you need (i.e. constructor, push(frame), pop(), size(), ...)

For thread-safety you may consider protecting your queue-like class methods with a class internal std::mutex, better with std::lock_guard<>.
An even better approach would be to use a lock-free container, more complex to be written correctly, but you can find some implementations on the web or github.

roalz
  • 2,699
  • 3
  • 25
  • 42
1

Solution for the recording with high fps is using image Acquisition Toolbox from MATLAB which support GigE and GenIcam. Using the ROI as 1000x700 I would achieve 150fps and this was possible with a Processor of 32GBRam and high processing speed. Normally with 8GB ram and i7 Processor I could achieve 50fps. Furthermore for better quality of the images, changing the exposure time to 1000 microseconds was best option. In Image acquisition Toolbox, there is an option of logging the data in memory or disk. Logging in memory is better option since the data is exported after stopping the acquisition while logging data into disk, data is written in simultaneoustly.

Reddy2810
  • 312
  • 2
  • 17