Skip to content

cornerSubPix

Image processingfunctionOpenCV 5.0.0
import { cornerSubPix } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Refines the corner locations.

The function iterates to find the sub-pixel accurate location of corners or radial saddle points as described in [forstner1987fast], and as shown on the figure below.

image

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  \cdot (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.

cornerSubPix(image: Mat, corners: Mat, winSize: Size, zeroZone: Size, criteria: TermCriteria): void;
image

Input single-channel, 8-bit or float image.

corners

Input/output value, modified by the native operation. Initial coordinates of the input corners and refined coordinates provided for output.

winSize

Half of the side length of the search window. For example, if winSize=Size(5,5) , then a (5*2+1) \times (5*2+1) = 11 \times 11 search window is used.

zeroZone

Half of the size of the dead region in the middle of the search zone over which the summation in the formula below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such a size.

criteria

Criteria for termination of the iterative process of corner refinement. That is, 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.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.