How to do it...

  1. Import the necessary packages:
import sys 
import cv2 
import numpy as np 
  1. 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) 
  1. Implement the Harris corner detection scheme:
image_harris1 = cv2.cornerHarris(image_gray2, 7, 5, 0.04) 
  1. Dilate the input image and construct the corners:
image_harris2 = cv2.dilate(image_harris1, None) 
  1. Implement image thresholding:
image[image_harris2 > 0.01 * image_harris2.max()] = [0, 0, 0] 
  1. Display the input image:
cv2.imshow('Harris Corners', image) 
  1. Wait for the instruction from the operator:
cv2.waitKey() 
  1. The command used to execute ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.