Reputation: 71
I have this method :
void Session::onNewImage(cv::Mat& img, double elapsedTime){
static int count = 0;
add(img, dnnOutput[count++], curLati, curLongi, curAlti, curHeading, curRoll);
}
It's been called 1400 times. Each time the value of "count" is incremented. But when it comes at 1401 time, I want "count" to become 0 , and then again increment form there. I don't want "count" to be a global variable. How can i achieve this ?
P.S. I cannot hard code it as 1400. It can be different everytime. There is another method which decides how many times this method will be called, Depending on number of images given as input to that method.
Upvotes: 3
Views: 803
Reputation: 38277
This should do it:
void Session::onNewImage(cv::Mat& img, double elapsedTime){
static int count = 0;
if (count >= getYourCountLimitFromSomewhere())
count = 0;
add(img, dnnOutput[count++], curLati, curLongi, curAlti, curHeading, curRoll);
}
Note that as @Aconcagua has pointed out in the comments, whether the comparison of count
with the threshold is via >
or >=
depends on the meaning of the getYourCountLimitFromSomewhere()
return value.
Upvotes: 2