Detecting corner location in subpixel
Subpixel corners can be found using OpenCV’s built-in feature. Using the dot product methodology, it refines corners identified by previous systems, such as the corner harris detector. Iterative refining occurs once a termination criteria is met.
cv.cornerSubPixel
Refines the corner locations. Checks the location of the corners and adjusts the position by comparing directions of gradients at that corner image.
cv2.cornerSubPix(image, corners, winSize, zeroZone, criteria)
Parameter:
- image: Input image.
- corners: As the name suggests, this array stores the approximate corners at the start of the process. As a result of the function, this array is modified with revised corner positions.
- winSize: This function relies on a number of equations to perform its job. Several pixels around the corner are used to get this effect, as well. If you use winSize, you may control how many pixels are extracted from a certain window.
- zeroZone: This function also solves numerous equations using the same way. When it comes to “solving” problems, a matrix is used. This matrix is inverted in order to find a solution to this problem. But some matrices cannot be inverted. Some pixels surrounding the corner are ignored to prevent this. That area is zeroZone.
- criteria: Criteria for stopping the iterative corner refinement procedure. To put it another way, the process of refining the angle of the corner comes to an end either once a set of conditions is met.(
cv.TERM_CRITERIA_EPSorcv.TermCriteria_COUNTor both)
Returns:
- corners: Array of refined corner points as a
numpy.ndarrayof shape(4, 1, 2)
Example:
Excerpt from the official tutorial page script.
# Set the needed parameters to find the refined corners
winSize = (5, 5)
zeroZone = (-1, -1)
criteria = (cv.TERM_CRITERIA_EPS + cv.TermCriteria_COUNT, 40, 0.001)
# Calculate the refined corner locations
corners = cv.cornerSubPix(src_gray, corners, winSize, zeroZone, criteria)
cv.TermCriteria
| Enumerator | Description |
|---|---|
| COUNT | the maximum number of iterations or elements to compute |
| MAX_ITER | ditto |
| EPS | the desired accuracy or change in parameters at which the iterative algorithm stops |