Python | Corner detection with Harris Corner Detection method using OpenCV
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:
Last Updated :
04 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...