Push & Pop a frame out of Mat vector
I have a vector
The issue is i am using 2 USB cameras and i want to grab both frames in frame_queue vector. But i am not able to use this code to push
frame_queue[i].pushback(frame);
Here is a sample code i am using :
//Make an instance of CameraStreamer
CameraStreamer cam(capture_index);
while (waitKey(20) != 27)
{
//Retrieve frames from each camera capture thread
for (size_t i = 0; i < capture_index.size(); i++)
{
Mat frame;
//Pop frame from queue and check if the frame is valid
cam.frame_queue[i].push_back(frame);
//if (cam.frame_queue[i]->try_pop(frame)){
//Show frame on Highgui window
imshow(label[i], frame);
//}
}
}
frame_queue is declared as vector<mat> frame_queue. And how to pop a frame from the frame_queue if i successfully push frames into it? How do i push and pop frames into and from frame_queue[i] ?
it's a bit unclear, what you're doing, perhaps it helps, if you show us your real code ?
please check the edited question.
Sorry it was a typo. But i got to know that there is pop_back(). i can write cam.frame_queue.push_back() but not cam.frame_queue[i].push_back(). I am not sure why.
hmm, if you want a
vector<Mat>
per cam, shouldn't it be:vector<vector<Mat>> frame_queue(2);
?push_back() and pop_back() do not work over a specific index i of your vector. They append and remove, respectively, one element at the end of vector, increasing or decreasing the vector size by one. If you want to access the i-th element of the vector, just do a simple assignation of Mat my_frame = frame_queue[i-th index] (maybe with a .clone() at the end depending on your scope).
well thank you for response. I figured out how to use concurrent_queue.h by installing TBB. I know this is not the answer for how to do it with vector<mat>. But i will try your suggestions for sure.