Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does cv::TermCriteria work in opencv?

Tags:

c++

opencv

I want to use the opencv function cv::cornerSubPix() for that I need another one, the cv::TermCriteria my question is about the last parameter of this function :

cv::TermCriteria(cv::TermCriteria::MAX_ITER +
                cv::TermCriteria::EPS,
                50, // max number of iterations
                0.0001)); // min accuracy

what does the min accuracy here mean?

like image 467
Engine Avatar asked Sep 23 '13 09:09

Engine


2 Answers

The structure of TermCriteria is

TermCriteria(

int type, // CV_TERMCRIT_ITER, CV_TERMCRIT_EPS, or both

int maxCount,

double epsilon
);

Typically we use the TermCriteria() function to generate the structure we need. The first argument of this function is either CV_TERMCRIT_ITER or CV_TERMCRIT_EPS, which tells the algorithm that we want to terminate either after some number of iterations or when the convergence metric reaches some small value (respectively). The next two arguments set the values at which one, the other, or both of these criteria should terminate the algorithm.

The reason we have both options is so we can set the type to CV_TERMCRIT_ITER | CV_TERMCRIT_EPS and thus stop when either limit is reached.

like image 135
Anand Avatar answered Nov 05 '22 09:11

Anand


The exact meaning of the epsilon term depends on the algorithm for which the termination criteria is intended. (See pp 299-300 of the Learning OpenCV book for some more details on cvTermCriteria)

Here, specifically, from the documentation:

... the process of corner position refinement stops either after criteria.maxCount iterations or when the corner position moves by less than criteria.epsilon on some iteration.

So the epsilon term specifies the accuracy you require in your subpixel values, for example a value of 0.0001 means you are asking for subpixel values down to an accuracy of 1/10000th of a pixel. (See p 321 of the Learning OpenCV book)

like image 4
Slothworks Avatar answered Nov 05 '22 10:11

Slothworks