Harris Corner Detection Algorithm is a mathematical technique to identify the internal corners of an image. Within this, the corners of an image are 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.
We will now look at the implementation of Harris Corner Detection Algorithm for Images using Python and OpenCV but if you are a beginner in the world of computer vision, it will be good to understand the basics at Python for Computer Vision with OpenCV.
Let’s now take a look at the syntax of the function:
Syntax of Function:
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)
Source Code to identify corners using Harris Algorithm
import cv2
import numpy as np
img = cv2.imread('robot.jpg')
operatedImage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dest = cv2.cornerHarris(operatedImage, 2, 5, 0.07)
# 2 is block size, 5 is Aperture parameter, 0.07 Harris detector free parameter
dest = cv2.dilate(dest, None)
img[dest > 0.01*dest.max()]=[0, 0, 255]
cv2.imshow('Harris', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("image_robo.jpg",edges)
Output image