天天看點

Harris corner detector algorithm

Harris and Stephens[3] improved upon Moravec's corner detector by considering the differential of the corner score with respect to direction directly, instead of using shifted patches. (This corner score is often referred to asautocorrelation, since the term is used in the paper in which this detector is described. However, the mathematics in the paper clearly indicate that the sum of squared differences is used.)

Without loss of generality, we will assume a grayscale 2-dimensional image is used. Let this image be given by

Harris corner detector algorithm

. Consider taking an image patch over the area

Harris corner detector algorithm

and shifting it by

Harris corner detector algorithm

. The weightedsum of squared differences (SSD) between these two patches, denoted

Harris corner detector algorithm

, is given by:

Harris corner detector algorithm
Harris corner detector algorithm

can be approximated by aTaylor expansion. Let

Harris corner detector algorithm

and

Harris corner detector algorithm

be thepartial derivatives of

Harris corner detector algorithm

, such that

Harris corner detector algorithm

This produces the approximation

Harris corner detector algorithm

which can be written in matrix form:

Harris corner detector algorithm

where A is the structure tensor,

Harris corner detector algorithm

This matrix is a Harris matrix, and angle brackets denote averaging (i.e. summation over

Harris corner detector algorithm

). If a circular window (or circularly weighted window, such as aGaussian) is used, then the response will be isotropic.

A corner (or in general an interest point) is characterized by a large variation of

Harris corner detector algorithm

in all directions of the vector

Harris corner detector algorithm

. By analyzing the eigenvalues of

Harris corner detector algorithm

, this characterization can be expressed in the following way:

Harris corner detector algorithm

should have two "large" eigenvalues for an interest point. Based on the magnitudes of the eigenvalues, the following inferences can be made based on this argument:

  1. If
    Harris corner detector algorithm
    and
    Harris corner detector algorithm
    then this pixel
    Harris corner detector algorithm
    has no features of interest.
  2. If
    Harris corner detector algorithm
    and
    Harris corner detector algorithm
    has some large positive value, then an edge is found.
  3. If
    Harris corner detector algorithm
    and
    Harris corner detector algorithm
    have large positive values, then a corner is found.

Harris and Stephens note that exact computation of the eigenvalues is computationally expensive, since it requires the computation of asquare root, and instead suggest the following function

Harris corner detector algorithm

, where

Harris corner detector algorithm

is a tunable sensitivity parameter:

Harris corner detector algorithm

Therefore, the algorithm does not have to actually compute the eigenvalue decomposition of the matrix

Harris corner detector algorithm

and instead it is sufficient to evaluate thedeterminant and trace of

Harris corner detector algorithm

to find corners, or rather interest points in general.

followings are excerpt from opencv tutorial.

How does it work?¶

  • Let’s look for corners. Since corners represents a variation in the gradient in the image, we will look for this “variation”.
  • Consider a grayscale image
    Harris corner detector algorithm
    . We are going to sweep a window
    Harris corner detector algorithm
    (with displacements
    Harris corner detector algorithm
    in the x direction and
    Harris corner detector algorithm
    in the right direction)
    Harris corner detector algorithm
    and will calculate the variation of intensity.
    Harris corner detector algorithm
    where:
    • Harris corner detector algorithm
      is the window at position
      Harris corner detector algorithm
    • Harris corner detector algorithm
      is the intensity at
      Harris corner detector algorithm
    • Harris corner detector algorithm
      is the intensity at the moved window
      Harris corner detector algorithm
  • Since we are looking for windows with corners, we are looking for windows with a large variation in intensity. Hence, we have to maximize the equation above, specifically the term:
    Harris corner detector algorithm
  • Using Taylor expansion:
    Harris corner detector algorithm
  • Expanding the equation and cancelling properly:
    Harris corner detector algorithm
  • Which can be expressed in a matrix form as:
    Harris corner detector algorithm
  • Let’s denote:
    Harris corner detector algorithm
  • So, our equation now is:
    Harris corner detector algorithm
  • A score is calculated for each window, to determine if it can possibly contain a corner:
    Harris corner detector algorithm
    where:
    • det(M) =
      Harris corner detector algorithm
    • trace(M) =
      Harris corner detector algorithm
    a window with a score
    Harris corner detector algorithm
    greater than a certain value is considered a “corner”

cv::cornerEigenValsAndVecs¶

Comments from the Wiki

void cornerEigenValsAndVecs (const Mat&  src, Mat&  dst, int  blockSize, int  apertureSize, int  borderType=BORDER_DEFAULT ) ¶
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
Parameters:
  • src – Input single-channel 8-bit or floating-point image
  • dst – Image to store the results. It will have the same size as  src  and the type  CV_32FC(6)
  • blockSize – Neighborhood size (see discussion)
  • apertureSize – Aperture parameter for the  Sobel()  operator
  • boderType – Pixel extrapolation method; see  borderInterpolate()

For every pixel

Harris corner detector algorithm

, the function cornerEigenValsAndVecs considers a blockSize

Harris corner detector algorithm

blockSize neigborhood

Harris corner detector algorithm

. It calculates the covariation matrix of derivatives over the neighborhood as:

Harris corner detector algorithm

Where the derivatives are computed using Sobel() operator.

After that it finds eigenvectors and eigenvalues of

Harris corner detector algorithm

and stores them into destination image in the form

Harris corner detector algorithm

where

  • Harris corner detector algorithm
    are the eigenvalues of
    Harris corner detector algorithm
    ; not sorted
  • Harris corner detector algorithm
    are the eigenvectors corresponding to
    Harris corner detector algorithm
  • Harris corner detector algorithm
    are the eigenvectors corresponding to
    Harris corner detector algorithm

The output of the function can be used for robust edge or corner detection.

See also: cornerMinEigenVal() , cornerHarris() , preCornerDetect()

cv::cornerHarris¶

Comments from the Wiki

void cornerHarris (const Mat&  src, Mat&  dst, int  blockSize, int  apertureSize, double  k, int  borderType=BORDER_DEFAULT ) ¶
Harris edge detector.
Parameters:
  • src – Input single-channel 8-bit or floating-point image
  • dst – Image to store the Harris detector responses; will have type  CV_32FC1  and the same size as  src
  • blockSize – Neighborhood size (see the discussion of  cornerEigenValsAndVecs() )
  • apertureSize – Aperture parameter for the  Sobel()  operator
  • k – Harris detector free parameter. See the formula below
  • boderType – Pixel extrapolation method; see  borderInterpolate()

The function runs the Harris edge detector on the image. Similarly to cornerMinEigenVal() and cornerEigenValsAndVecs() , for each pixel

Harris corner detector algorithm

it calculates a

Harris corner detector algorithm

gradient covariation matrix

Harris corner detector algorithm

over a

Harris corner detector algorithm

neighborhood. Then, it computes the following characteristic:

Harris corner detector algorithm

Corners in the image can be found as the local maxima of this response map.