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…

  1. Create a new Python file, and import the following packages:
    import sys
    
    import cv2
    import numpy as np
  2. 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)
  3. 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)
  4. Run the Harris corner detector ...

Get Python: Real World Machine Learning 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.