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 pattern | Region type | Visual meaning |
|---|---|---|
| Both small | Flat area | Uniform brightness, no texture |
| One large, one small | Edge | Strong change across a single direction |
| Both large | Corner | Strong change in all directions |
| Both large but noisy | Textured region | Repeated detail, weak localization |
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.
| Parameter | Typical value | Effect of increasing it |
|---|---|---|
| Sensitivity constant k | 0.04 to 0.06 | Fewer corners, stronger edge rejection |
| Gaussian window sigma | 1 to 2 pixels | Smoother response, coarser localization |
| Derivative aperture | 3 × 3 Sobel kernel | Less noise, more blurred gradients |
| Response threshold | About 1% of the maximum R | Fewer and stronger corners |
| Suppression radius | 1 to 3 pixels | Sparser, better separated keypoints |
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.
| Detector | Core criterion | Scale invariance | Typical use |
|---|---|---|---|
| Harris | det(M) − k · trace(M)² | No | Calibration, tracking, teaching |
| Shi-Tomasi | Minimum eigenvalue of M | No | Optical flow feature selection |
| FAST | Contiguous ring of brighter or darker pixels | No | Real-time embedded systems |
| SIFT | Difference-of-Gaussians extrema | Yes | Robust matching across zoom |
| ORB | FAST with Harris ranking and pyramid | Partial | Fast SLAM and mobile apps |
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.
| Symptom | Likely cause | Recommended fix |
|---|---|---|
| Corners vanish after zooming | No scale invariance | Run on an image pyramid or use SIFT |
| Many spurious points on noise | Window sigma too small | Increase Gaussian smoothing |
| Clusters of adjacent corners | Missing suppression | Apply non-maximum suppression |
| Few corners in dark images | Fixed absolute threshold | Use a relative threshold or top N |
| Inaccurate corner position | Pixel-level maxima only | Apply sub-pixel refinement |
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.