cornerSubPix

Description

Refines the corner locations.

Signature

cv2.cornerSubPix(image, corners, winSize, zeroZone, criteria) → corners

Parameters

Explanation

The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as shown on the figure below. The functions cornerHarris or findContours will return integer values for corners, and cornerSubPix will refine those to more accurate locations (the subpixel location values). Please see this link for complete examples.

The sub-pixel accurate corner locator is based on the observation that every vector from the center \(q\) to a point \(p\) located within a neighborhood of q is orthogonal to the image gradient at p subject to image and measurement noise. Consider the expression: $$\epsilon_i=DI_{p_i}^T\ast(q-p_i)$$ where \(DI_{p_i}\) is an image gradient at one of the points \(p_i\) in a neighborhood of q. The value of q is to be found so that \(\epsilon_i\) is minimized. A system of equations may be set up with \(\epsilon_i\) set to zero: $$\sum_i(DI_{p_i}\ \cdot\ \ DI_{p_i}\ ^T)\cdot\ q\ -\ \sum_i(DI_{p_i}\ \ \cdot\ DI_{p_i}\ \ ^T\cdot\ p_i)$$ where the gradients are summed within a neighborhood ("search window") of q . Calling the first gradient term G and the second gradient term b gives: $$q=\ G^{-1}\ \ \cdot\ b$$ The algorithm sets the center of the neighborhood window at this new center q and then iterates until the center stays within a set threshold.

Notes


References

Created with OpenCV 4.4.0