Harris corner detector

Also known as: Harris corner detection

On this page 7

The Harris corner detector is a classic computer vision algorithm that locates corners, meaning image points where brightness changes sharply in every direction, by analyzing a small matrix of local image gradients. Introduced by Chris Harris and Mike Stephens in 1988, it remains a reference method for corner detection in computer vision and a building block of many feature pipelines.

Its central idea is the second-moment matrix (also called the structure tensor), which summarizes how a small window would change if it were shifted slightly. A flat region changes little in any direction, an edge changes in one direction only, and a corner changes in all directions. The detector turns that observation into a single corner response score that is fast to compute and invariant to rotation.

How the Harris corner detector measures local change

The Harris corner detector measures how much the sum of squared differences inside a window grows when the window moves by a small offset. Using a first-order Taylor expansion, that change is approximated by a quadratic form built from the image derivatives Ix and Iy, so the algorithm never has to test shifts explicitly.

For every pixel, the products Ix², Iy² and IxIy are computed and then smoothed with a Gaussian window, typically with a sigma of 1 to 2 pixels. These three smoothed values form the symmetric 2 × 2 matrix M. The two eigenvalues of M describe the strength of intensity change along the two principal directions of the window.

The following table shows how the eigenvalues of the second-moment matrix classify each image region.

Eigenvalue patternRegion typeVisual meaning
Both smallFlat areaUniform brightness, no texture
One large, one smallEdgeStrong change across a single direction
Both largeCornerStrong change in all directions
Both large but noisyTextured regionRepeated detail, weak localization
Eigenvalue patterns and the region type they indicate

The corner response function and its parameters

Instead of computing eigenvalues directly, Harris defined the response R = det(M) − k · trace(M)², which depends on the eigenvalues only through their product and sum. This choice avoids square roots and keeps the computation cheap. A large positive R indicates a corner, a negative R an edge, and a value near zero a flat region.

After the response map is computed, two post-processing steps produce the final keypoints: a threshold on R removes weak responses, and non-maximum suppression keeps only the local maximum within a small neighborhood, usually 3 × 3 or 5 × 5 pixels. The table below lists the parameters that most affect the result.

ParameterTypical valueEffect of increasing it
Sensitivity constant k0.04 to 0.06Fewer corners, stronger edge rejection
Gaussian window sigma1 to 2 pixelsSmoother response, coarser localization
Derivative aperture3 × 3 Sobel kernelLess noise, more blurred gradients
Response thresholdAbout 1% of the maximum RFewer and stronger corners
Suppression radius1 to 3 pixelsSparser, better separated keypoints
Main parameters of the Harris corner detector

A practical warning applies here: the absolute value of R depends on image contrast and on the scale of the gradients, so a fixed numeric threshold rarely transfers between datasets. Relative thresholds or selecting the top N responses are more robust choices.

Harris compared with other corner and keypoint detectors

The Harris corner detector sits at the start of a long family of interest point detectors. It is precise and rotation invariant but not scale invariant, which is the main reason later methods such as SIFT and ORB added scale-space search and descriptors. The comparison below places Harris among its closest neighbors.

DetectorCore criterionScale invarianceTypical use
Harrisdet(M) − k · trace(M)²NoCalibration, tracking, teaching
Shi-TomasiMinimum eigenvalue of MNoOptical flow feature selection
FASTContiguous ring of brighter or darker pixelsNoReal-time embedded systems
SIFTDifference-of-Gaussians extremaYesRobust matching across zoom
ORBFAST with Harris ranking and pyramidPartialFast SLAM and mobile apps
Harris compared with related detectors

The Shi-Tomasi variant, also known as Good Features to Track, replaces the Harris score with the smaller eigenvalue and often yields more stable points for tracking. ORB still uses the Harris score to rank its FAST keypoints, which shows that the original response remains useful decades later.

Where the detector is used in practice

The Harris corner detector is valued where precise localization matters more than invariance to large changes in scale. Corners are distinctive in two dimensions, so they avoid the aperture problem that makes edge points ambiguous along their own direction.

  • Camera calibration, where checkerboard corners are refined to sub-pixel accuracy.
  • Feature tracking across video frames, combined with optical flow methods.
  • Image registration and mosaicking when frames share similar scale.
  • Visual odometry in robotics, often through Harris-ranked ORB features.
  • Teaching and benchmarking, because the mathematics is compact and transparent.

Libraries such as OpenCV expose the algorithm directly through the function cornerHarris, and a related function, goodFeaturesToTrack, offers both the Harris and Shi-Tomasi criteria with built-in thresholding and minimum-distance filtering.

Limitations and common mistakes

The detector has known failure modes that experienced practitioners plan for. Its response changes when an image is zoomed, it is sensitive to noise and blur, and it produces clusters of responses on high-contrast texture. The table summarizes frequent symptoms and their fixes.

SymptomLikely causeRecommended fix
Corners vanish after zoomingNo scale invarianceRun on an image pyramid or use SIFT
Many spurious points on noiseWindow sigma too smallIncrease Gaussian smoothing
Clusters of adjacent cornersMissing suppressionApply non-maximum suppression
Few corners in dark imagesFixed absolute thresholdUse a relative threshold or top N
Inaccurate corner positionPixel-level maxima onlyApply sub-pixel refinement
Common problems with Harris corners

A frequent misconception is that Harris provides a descriptor for matching. It only provides locations and scores; matching requires a separate descriptor such as image patches, BRIEF or SIFT descriptors, followed by feature matching and outlier rejection.

In plain words

Imagine sliding a small square window over a photo. On a blank wall, moving the window changes nothing. On the edge of a table, moving along the edge changes nothing either. At the corner of the table, any movement changes what you see.

The Harris corner detector does exactly this test with simple math. It marks the spots where every small move causes a big change. These spots are easy to find again in another photo. That makes them reliable landmarks for computers that compare images or follow motion.

A real-world example

A robotics team calibrates a stereo camera rig before mounting it on a warehouse robot. They print a checkerboard with 9 × 6 inner corners and capture about 20 images at different angles. The calibration software applies a Harris-style corner response, keeps the strongest local maxima, and then refines each corner to sub-pixel accuracy.

With these precise corner positions, the solver estimates focal length, lens distortion and the relative pose of the two cameras. The team typically reaches a reprojection error below 0.3 pixels. Accurate calibration then lets the robot estimate shelf distances reliably, which reduces collisions and misplaced picks during navigation.