<a id="easyimage-harris-corner-detector"></a>

# Harris Corner Detector

The Harris corner detector identifies corners in an image by analyzing how the image intensity changes in a small window around each pixel, in all directions. If shifting the window in any direction produces a large intensity change, the point is likely a corner (as opposed to an edge, where the change is large in only one direction, or a flat region, where it’s small in all directions). It computes this using the local gradients to build a matrix (the structure tensor) whose eigenvalues indicate the strength and nature of intensity variation, then derives a “corner response” score from that matrix to flag strong corner candidates. The Harris corner detector is invariant to rotation, illumination variation and image noise. It delivers a vector of points of interest.

![](assets/images/easyimage/harriscornerdetectorexample.webp)

The **EasyImage** Harris corner detector requires three parameters:

* The integration scale $σ_{i}$: the standard deviation of the Gaussian Filter used for scale analysis. $σ_{d} = 0.7 \times σ_{i}$, where $σ_{d}$ is the differentiation scale: the standard deviation of the Gaussian Filter used for noise reduction during computation of the gradient.
* A corner threshold: a fraction ranging from 0 to 1 of the maximum value of the cornerness of the source image.
* A Boolean that toggles sub-pixel detection.

The following characteristics are available for every point of interest:

* Corner position (pixel coordinates with sub-pixel accuracy if enabled).
* Cornerness measurement.
* Gradient magnitude in regard to the differentiation scale $σ_{d}$.
* Gradient value along the X-axis in regard to the differentiation scale $σ_{d}$.
* Gradient value along the Y-axis in regard to the differentiation scale $σ_{d}$.

The API of the Harris corner detector is a single class named [`EHarrisCornerDetector`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html) and these methods:

* [`EHarrisCornerDetector::Apply`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a74cfb631d046c62853e937faf9078563) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#ad5f7dc2a616d485ca7742a54da25fe7f) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#af59f372a12fc2d5dbbf7ff089c5afd05): applies the Harris corner detector on an image/ROI.
* [`EHarrisCornerDetector`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html): constructs a [`EHarrisCornerDetector`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html) object initialized to its default values.
* [`EHarrisCornerDetector::GetDerivationScale`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a9c04301c28e1c5ac5406df3f2086ed92) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a67fca7181747e0a8db414b4ab07d425a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#ac424c1a93ab342b8a9ec493ae97fa655): returns or sets the current derivation scale.
* [`EHarrisCornerDetector::GetIntegrationScale`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#af065a8ee263e0941201d791ce6661096) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#adaeacbbf51ea64eeac2232ce09caf79b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a89403eaef756c56cf64c46e8597b87f6): returns or sets the integration scale.
* [`EHarrisCornerDetector::GetThreshold`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a57097b62c2801c3b7260c0c4b568aed7) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a3a46701eb63a0a22116a5eb0fe21f452) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a773a8b1fc3afd0779f2b1eee885c870f): returns the current threshold or sets the threshold on the cornerness measure for a pixel to be considered as a corner.
* [`EHarrisCornerDetector::GetThresholdingMode`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#afdd5e9f189b11f233fc9afc552aaa4a2) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a69d2e98f6edf3fb0068a233e82cb7ca8) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a76d7173e5b24b6147d2367d47bc0d979) / [`EHarrisCornerDetector::SetThresholdingMode`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a0da381bfb1420f73f8efa7513d52801d) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a69d2e98f6edf3fb0068a233e82cb7ca8) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a76d7173e5b24b6147d2367d47bc0d979): returns or sets the current thresholding mode for the cornerness measure.
* [`EHarrisCornerDetector::GetGradientNormalizationEnabled`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a8de14a71915819b0a1bd6e8236b721fa) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a5564457aa7e2ae94ab06dc28f1ccae8b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a25cfadaf5532d4a684d6a946f1455f56): returns whether the gradient is normalized before the computation of the cornerness measure.
* [`EHarrisCornerDetector::GetSubpixelPrecisionEnabled`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a6e0e18a58804a1f4d7fab9570bf1e115) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#acc272a809af8844ac4e48c8318118fd9) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a87087947f8c2f8e516176f5c6db6290f): returns whether the sub-pixel interpolation is enabled.
* [`EHarrisCornerDetector::SetGradientNormalizationEnabled`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#acd66fe3ca40c73b4109379f20be584cb) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#a5564457aa7e2ae94ab06dc28f1ccae8b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a25cfadaf5532d4a684d6a946f1455f56): sets whether the gradient is normalized before the computation of the cornerness measure.
* [`EHarrisCornerDetector::SetSubpixelPrecisionEnabled`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a937fe0fbf8f34335b9235f68155bfc16) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#acc272a809af8844ac4e48c8318118fd9) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a87087947f8c2f8e516176f5c6db6290f): sets whether the sub-pixel interpolation is enabled.

<a id="easyimage-harris-corner-detector-basic-usage"></a>

## Basic Usage of Harris Corner Detector

An object of the [`EHarrisCornerDetector`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html) class can be reused across Harris detector applications in order to reduce the setup time.

1. **Create an instance of the detector** and set the appropriate method, for instance, the integration scale, [`EHarrisCornerDetector::SetIntegrationScale`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a1a6aa8b7f93bd29303118228355fc893) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#adaeacbbf51ea64eeac2232ce09caf79b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#a89403eaef756c56cf64c46e8597b87f6), with the structures of interest that could have a spatial extent of 2 pixels.
2. [`EHarrisCornerDetector::Apply`](../../../doxygen_cpp/classeVision_1_1EHarrisCornerDetector.html#a74cfb631d046c62853e937faf9078563) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisCornerDetector.html#ad5f7dc2a616d485ca7742a54da25fe7f) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisCornerDetector.html#af59f372a12fc2d5dbbf7ff089c5afd05) **the detector** with two arguments to the new image : the input image and the interest points in the input image [`EHarrisInterestPoints`](../../../doxygen_cpp/classeVision_1_1EHarrisInterestPoints.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EHarrisInterestPoints.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EHarrisInterestPoints.html).
3. Access the individual elements of the output vector.

<a id="easyimage-harris-corner-detector-quick-links"></a>

## See Also

Easy to understand, ready to copy code snippets.

Detect edges in an image using gradient magnitudes and hysteresis thresholding.
