Harris Corner detection algorithm was developed to identify the internal corners of an image. The corners of an image are basically identified as the regions in which there are variations in large intensity of the gradient in all possible dimensions and directions. Corners extracted can be a part of the image features, which can be matched with features of other images, and can be used to extract accurate information. Harris Corner Detection is a method to extract the corners from the input image and to extract features from the input image.
About the function used:
Syntax: cv2.cornerHarris(src, dest, blockSize, kSize, freeParameter, borderType)
Parameters:
src – Input Image (Single-channel, 8-bit or floating-point)
dest – Image to store the Harris detector responses. Size is same as source image
blockSize – Neighborhood size ( for each pixel value blockSize * blockSize neighbourhood is considered )
ksize – Aperture parameter for the Sobel() operator
freeParameter – Harris detector free parameter
borderType – Pixel extrapolation method ( the extrapolation mode used returns the coordinate of the pixel corresponding to the specified extrapolated pixel )
Below is the Python implementation :
Python3
import cv2
import numpy as np
image = cv2.imread( 'GeekforGeeks.jpg' )
operatedImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
operatedImage = np.float32(operatedImage)
dest = cv2.cornerHarris(operatedImage, 2 , 5 , 0.07 )
dest = cv2.dilate(dest, None )
image[dest > 0.01 * dest. max ()] = [ 0 , 0 , 255 ]
cv2.imshow( 'Image with Borders' , image)
if cv2.waitKey( 0 ) & 0xff = = 27 :
cv2.destroyAllWindows()
|
Input:

Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
04 Jan, 2023
Like Article
Save Article