I'm trying to implement a circular buffer for my program. The buffer is used to share data between two threads as shown below. I use OpenCV to grab video frames from camera (Thread 1). Then I would like to store this data in a circular buffer, so that Thread 2 can get the data from the buffer.
How can I implement a circular buffer for cv::Mat
objects in C++? I know how to create circular buffer for standard C++ objects (like int
or char
) but I can't make it work with objects of type cv::Mat
.
Any suggestions?
cbWrite
shouldn't the check be forcb->end==cb->size
(to resetcb->end = 0
to avoid buffer overruns? I realize this probably isn't what is leading to the crash but it still looks dangerous. – Refection