Edge detection is one of the most popular techniques in Computer Vision. It is used as a preprocessing step in many applications. Let's look at how to use different edge detectors to detect edges in the input image.
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
# Load the input image -- 'chair.jpg' # Convert it to grayscale input_file = sys.argv img = cv2.imread(input_file, cv2.IMREAD_GRAYSCALE)
- Extract the height and width of the image:
h, w = img.shape
- Sobel filter is a type of edge detector that uses a 3x3 kernel to detect horizontal and vertical edges separately. You can learn more about it at http://www.tutorialspoint.com/dip/sobel_operator.htm ...