Detecting edges in images
Edge detection is used to detect the borders in images. It provides the details regarding the shape and the region properties. This includes perimeter, major axis size, and minor axis size.
How to do it...
- Import the necessary packages:
import sys import cv2 import numpy as np
- Read the input image:
in_file = sys.argv[1] image = cv2.imread(in_file, cv2.IMREAD_GRAYSCALE)
- Implement the Sobel edge detection scheme:
horizontal_sobel = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=5) vertical_sobel = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=5) laplacian_img = cv2.Laplacian(image, cv2.CV_64F) canny_img = cv2.Canny(image, 30, 200)
- Display the input image and its corresponding output:
cv2.imshow('Original', image) cv2.imshow('horizontal Sobel', horizontal_sobel) cv2.imshow('vertical Sobel', vertical_sobel) cv2.imshow('Laplacian image', laplacian_img) cv2.imshow('Canny image', canny_img)
- Wait for the instruction from the operator:
cv2.waitKey()
- Display the input image and the...