Detecting corners in images
Corners are borders in images used to extract special features that infer the content of an image. Corner detection is frequently used in image registration, video tracking, image mosaics, motion detection, 3D modelling, panorama stitching, and object recognition.
How to do it...
- 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...