Corner Detection
Learn to detect corners in images with template matching, Harris Corner Detection, and Good Features to Track.
We'll cover the following...
Corners are salient features in an image that we might want to find to locate or track an object from frame to frame in a video sequence. Corners are peculiar points having a high rate of change in two perpendicular directions.
We’ll study the image shown by the code widget below. We must convert the image to grayscale since the corner detection functions accept grayscale images as input.
import cv2import numpy as npimport copyoriginal_img = cv2.imread('./images/paper/book_draw1.jpg')grayscale_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)cv2.imwrite('./output/0_original.png', original_img)cv2.imwrite('./output/1_grayscale.png', grayscale_img)
Our task for the rest of this lesson will be to locate the four book corners.
We’ll explore three techniques to detect corners:
Template matching
Harris Corner Detection
Good Features to Track
Template matching
The simplest way to detect corners is to use template matching with a synthetic template. The four corners will each have their template, with a white square in the corner of a black square.
Template matching of the grayscale image with templates of the four corners will highlight the light book corners on the dark background.
Let’s define the match_corner()
function that we’ll ...