I have strange problem. I am taking a set of photos of a sequential event via webcam and OpenCV. Storing them in a vector variable. At the end of the capture function, all I got is the last capture.
I think I have a fundamental problem with vectors. Functions are below
void eventCapture()
{
vector<cv::Mat> capturedAll;
getCaptures(capturedAll, 10, 500);
int csize = capturedAll.size();
// Here gives always the last capture
// It is not related with imshow
// imwrite also saves the last capture as wrong
for (int i = 0; i < 10; i++) {
cv::imshow("Images", capturedAll[i]);
string imgname = "imgcaps" + to_string(i) + ".jpg";
cv::imwrite(imgname, capturedAll[i]);
cv::waitKey(100);
}
}
void getCaptures(vector<cv::Mat>& capStore, int count, int tdif)
{
QElapsedTimer capTimer;
capTimer.start();
for (int i = 0; i < count; i++) {
capTimer.restart();
// get_capture takes a photo from webcam
cv::Mat capMat = webCam.get_capture();
capStore.push_back(capMat);
string imgname = "localsave" + to_string(i) + ".jpg";
// Saved image here is giving correct result
cv::imwrite(imgname, capMat);
while (!capTimer.hasExpired(tdif))
qApp->processEvents();
}
}
I also tried to use iterator but it has given same wrong result.