Python | Corner detection with Harris Corner Detection using OpenCV (original) (raw)

Last Updated : 11 Jun, 2026

Corners are points in an image where the intensity changes significantly in multiple directions. They typically occur at the intersection of edges or at locations with strong variations in brightness, making them important feature points in image analysis and computer vision tasks.

**Harris Corner Detection Function in OpenCV

Harris Corner Detection is a computer vision technique used to detect corners by analyzing intensity changes in multiple directions. It identifies points with strong variations in pixel values, which are useful for feature-based analysis. In OpenCV, it is implemented using cv2.cornerHarris(), which computes a corner response for each pixel.

**Function Syntax:

cv2.cornerHarris(src, blockSize, ksize, k)

**Parameters:

Implementing

Let’s see how to implement Harris Corner Detection and highlight the corners detected in an image. Here we will be using OpenCV, Numpy and Matplotlib libraries for the implementation.

You can download the image used from here.

import cv2 import numpy as np import matplotlib.pyplot as plt

image_path = "/content/sample_image.jpg"
image = cv2.imread(image_path)

operatedImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) operatedImage = np.float32(operatedImage)

dest = cv2.cornerHarris(operatedImage, 17, 21, 0.01) dest = cv2.dilate(dest, None)

image[dest > 0.01 * dest.max()] = [0, 0, 255] image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

plt.imshow(image_rgb) plt.title('Harris Corner Detection') plt.axis('off')
plt.show()

`

**Output:

output-harris

Output Image

Advantages

Challenges