- Import the necessary packages:
import sys import cv2 import numpy as np
- Load the input image:
in_file = sys.argv[1] image = cv2.imread(in_file) cv2.imshow('Input image', image) image_gray1 = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) image_gray2 = np.float32(image_gray1)
- Implement the Harris corner detection scheme:
image_harris1 = cv2.cornerHarris(image_gray2, 7, 5, 0.04)
- Dilate the input image and construct the corners:
image_harris2 = cv2.dilate(image_harris1, None)
- Implement image thresholding:
image[image_harris2 > 0.01 * image_harris2.max()] = [0, 0, 0]
- Display the input image:
cv2.imshow('Harris Corners', image)
- Wait for the instruction from the operator:
cv2.waitKey()
- The command used to execute the Detecting_corner.py Python program file, along with the input image (box.jpg), is shown here:
- The input image used to execute the Detecting_corner.py file is shown here:
- Harris Corners obtained after executing the Detecting_corner.py file are shown here:
In order to learn how it works for an input image, refer to the following:
- Image corner detection involves finding the edges/corners in the given picture. It can be used to extract the vital shape features from grayscale and RGB pictures. Refer to this survey paper on edge and corner detection:
https://pdfs.semanticscholar.org/24dd/6c2c08f5601e140aad5b9170e0c7485f6648.pdf.