I use a camera to get frames continuesly.In my code,i have use VideoCapture to do that. But when i debug,i find that the frame i got is the old frame. I have asked some guys, they told me that some old frames will store in the buffer and i should use a worker thread to get the latest frame.Also there is a similar question here. Similar question
Here, i have two questions,
If the buffer can store 5 frames and now have stored 5 frames, When does the buffer update?After 5 frames have been got out or just 1 frame? Because i want to know whether i got old frames all the time or i got one new frame then four old frames then change to one lastest frame...
I have debug my code, set a breakpoint at cap >> frame. First frame(loop) Put my hand in and second loop put my hand out of the camera, I found that the image will changed after few frames. Does it mean i got one new frame then four old frames then change to one lastest frame...?
2.Because it's my first time to use thread, i am not sure my code is wrong or not, here is my code,
void task(VideoCapture cap, Mat& frame) { while (true) { cap >> frame; } }
int main() {
Mat frame, image;
VideoCapture cap;
cap.open(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1600);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
cap >> frame;
thread t(task, cap, frame);
while (true) {
frame.copyTo(image);
...//image processing loop
}
}
I also have set breakpoint in task() to check the frame, but is the same condition. The image will changed after few frames.I don't know why. Is my code wrong or I can not set breakpoint to check like this as using thread? Can somebody help?Thank you very much.