I have a simple code whereby upon user input, the camera would capture an image. Here's the code:
for (int i=0; i<4; i++){
cvWaitKey(0); //wait for input then take picture
Mat grabbed = cam1.CamCapture();
Image[i].setImage(grabbed.clone());
imshow("picture", Image[i].getImage());
cvWaitKey(1);
}
The problem is where upon displaying the images, Image[i] is displaying the picture meant for Image[i-1].
I do not understand what seems to be problem as I would thought that upon entering the loop, I would have to press a key, then the camera would capture a picture and store it into the first object, Image[0] and the process is repeated for 4 times. This however does not seem to be the case.
I have a workaround at the moment which is using nested loops. int k; for (int i=0; i<4; i++){ cvWaitKey(0); //wait for input then take picture for (int k=0;i<5;k++){ Mat grabbed = cam1.CamCapture(); Image[i].setImage(grabbed.clone()); } imshow("picture", Image[i].getImage()); cvWaitKey(1); }
This however does not seem to be an efficient manner. I think the issue may be due to buffer issue but I am not too sure.
Please advice, thank you.