Detecting corners
Corner detection is an important process in Computer Vision. It helps us identify the salient points in the image. This was one of the earliest feature extraction techniques that was used to develop image analysis systems.
How to do it…
Create a new Python file, and import the following packages:
import sys import cv2 import numpy as np
Load the input image. We will use
box.png
:# Load input image -- 'box.png' input_file = sys.argv[1] img = cv2.imread(input_file) cv2.imshow('Input image', img)
Convert the image to grayscale and cast it to floating point values. We need the floating point values for the corner detector to work:
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img_gray = np.float32(img_gray)
Run the Harris corner detector function on the grayscale image. You can learn more about Harris corner detector at http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html:
# Harris corner detector img_harris = cv2.cornerHarris...