Skip to main content
This module provides functions for detecting various features in images, including edges, corners, lines, and circles.

Edge Detection

Canny

Finds edges in an image using the Canny algorithm.
InputArray
8-bit input image.
InputArray
16-bit x derivative of input image (CV_16SC1 or CV_16SC3).
InputArray
16-bit y derivative of input image (same type as dx).
OutputArray
Output edge map; single channels 8-bit image, which has the same size as image.
double
First threshold for the hysteresis procedure.
double
Second threshold for the hysteresis procedure.
int
default:"3"
Aperture size for the Sobel operator.
bool
default:"false"
A flag, indicating whether a more accurate L2 norm should be used to calculate the image gradient magnitude (L2gradient=true), or whether the default L1 norm is enough (L2gradient=false).
The function finds edges in the input image and marks them in the output map edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The largest value is used to find initial segments of strong edges.

Derivatives and Gradients

Sobel

Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
InputArray
Input image.
OutputArray
Output image of the same size and the same number of channels as src.
int
Output image depth. In the case of 8-bit input images it will result in truncated derivatives.
int
Order of the derivative x.
int
Order of the derivative y.
int
default:"3"
Size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
double
default:"1"
Optional scale factor for the computed derivative values; by default, no scaling is applied.
double
default:"0"
Optional delta value that is added to the results prior to storing them in dst.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
The Sobel operators combine Gaussian smoothing and differentiation. Most often, the function is called with (xorder = 1, yorder = 0, ksize = 3) or (xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative.

Scharr

Calculates the first x- or y- image derivative using Scharr operator.
InputArray
Input image.
OutputArray
Output image of the same size and the same number of channels as src.
int
Output image depth.
int
Order of the derivative x.
int
Order of the derivative y.
double
default:"1"
Optional scale factor for the computed derivative values.
double
default:"0"
Optional delta value that is added to the results prior to storing them in dst.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
The Scharr operator may give more accurate results than the 3×3 Sobel. The Scharr aperture is: [30310010303]\begin{bmatrix} -3 & 0 & 3 \\ -10 & 0 & 10 \\ -3 & 0 & 3 \end{bmatrix} for the x-derivative, or transposed for the y-derivative.

Laplacian

Calculates the Laplacian of an image.
InputArray
Source image.
OutputArray
Destination image of the same size and the same number of channels as src.
int
Desired depth of the destination image.
int
default:"1"
Aperture size used to compute the second-derivative filters. The size must be positive and odd.
double
default:"1"
Optional scale factor for the computed Laplacian values.
double
default:"0"
Optional delta value that is added to the results prior to storing them in dst.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator: Δsrc=2srcx2+2srcy2\Delta \text{src} = \frac{\partial^2 \text{src}}{\partial x^2} + \frac{\partial^2 \text{src}}{\partial y^2}

Corner Detection

cornerHarris

Harris corner detector.
InputArray
Input single-channel 8-bit or floating-point image.
OutputArray
Image to store the Harris detector responses. It has the type CV_32FC1 and the same size as src.
int
Neighborhood size.
int
Aperture parameter for the Sobel operator.
double
Harris detector free parameter.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
The function runs the Harris corner detector on the image. Corners in the image can be found as the local maxima of this response map.

cornerMinEigenVal

Calculates the minimal eigenvalue of gradient matrices for corner detection.
InputArray
Input single-channel 8-bit or floating-point image.
OutputArray
Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as src.
int
Neighborhood size.
int
default:"3"
Aperture parameter for the Sobel operator.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal eigenvalue of the covariance matrix of derivatives.

goodFeaturesToTrack

Determines strong corners on an image.
InputArray
Input 8-bit or floating-point 32-bit, single-channel image.
OutputArray
Output vector of detected corners.
int
Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned. maxCorners <= 0 implies that no limit on the maximum is set.
double
Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure.
double
Minimum possible Euclidean distance between the returned corners.
InputArray
default:"noArray()"
Optional region of interest.
int
default:"3"
Size of an average block for computing a derivative covariation matrix over each pixel neighborhood.
bool
default:"false"
Parameter indicating whether to use a Harris detector or cornerMinEigenVal.
double
default:"0.04"
Free parameter of the Harris detector.
The function finds the most prominent corners in the image or in the specified image region.

Hough Transform

HoughLines

Finds lines in a binary image using the standard Hough transform.
InputArray
8-bit, single-channel binary source image. The image may be modified by the function.
OutputArray
Output vector of lines. Each line is represented by a 2 or 3 element vector (ρ, θ) or (ρ, θ, votes).
double
Distance resolution of the accumulator in pixels.
double
Angle resolution of the accumulator in radians.
int
Accumulator threshold parameter. Only those lines are returned that get enough votes (>threshold).
double
default:"0"
For the multi-scale Hough transform, it is a divisor for the distance resolution rho.
double
default:"0"
For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
double
default:"0"
Minimum angle to check for lines. Must fall between 0 and max_theta.
double
default:"CV_PI"
Upper bound for the angle. Must fall between min_theta and CV_PI.
The function implements the standard or standard multi-scale Hough transform algorithm for line detection.

HoughLinesP

Finds line segments in a binary image using the probabilistic Hough transform.
InputArray
8-bit, single-channel binary source image. The image may be modified by the function.
OutputArray
Output vector of lines. Each line is represented by a 4-element vector (x₁, y₁, x₂, y₂), where (x₁,y₁) and (x₂, y₂) are the ending points of each detected line segment.
double
Distance resolution of the accumulator in pixels.
double
Angle resolution of the accumulator in radians.
int
Accumulator threshold parameter. Only those lines are returned that get enough votes (>threshold).
double
default:"0"
Minimum line length. Line segments shorter than that are rejected.
double
default:"0"
Maximum allowed gap between points on the same line to link them.
The function implements the probabilistic Hough transform algorithm for line detection.

HoughCircles

Finds circles in a grayscale image using the Hough transform.
InputArray
8-bit, single-channel, grayscale input image.
OutputArray
Output vector of found circles. Each vector is encoded as 3 or 4 element floating-point vector (x, y, radius) or (x, y, radius, votes).
int
Detection method. The available methods are HOUGH_GRADIENT and HOUGH_GRADIENT_ALT.
double
Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1, the accumulator has the same resolution as the input image.
double
Minimum distance between the centers of the detected circles.
double
default:"100"
First method-specific parameter. In case of HOUGH_GRADIENT and HOUGH_GRADIENT_ALT, it is the higher threshold of the two passed to the Canny edge detector.
double
default:"100"
Second method-specific parameter. In case of HOUGH_GRADIENT, it is the accumulator threshold for the circle centers at the detection stage.
int
default:"0"
Minimum circle radius.
int
default:"0"
Maximum circle radius. If <= 0, uses the maximum image dimension.
The function finds circles in a grayscale image using a modification of the Hough transform.
Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range (minRadius and maxRadius) if you know it.

Enumerations

HoughModes

Variants of Hough transform:
  • HOUGH_STANDARD - Classical or standard Hough transform
  • HOUGH_PROBABILISTIC - Probabilistic Hough transform (more efficient)
  • HOUGH_MULTI_SCALE - Multi-scale variant of the classical Hough transform
  • HOUGH_GRADIENT - 21HT for circles
  • HOUGH_GRADIENT_ALT - Variation of HOUGH_GRADIENT to get better accuracy