How to do it...

Here are the steps needed to complete this recipe:

  1. Import the modules:
import cv2import matplotlib.pyplot as plt
  1. Load the test image:
image = cv2.imread('../data/Lena.png')
  1. Detect the edges using the Canny algorithm:
edges = cv2.Canny(image, 200, 100)
  1. Visualize the results:
plt.figure(figsize=(8,5))plt.subplot(121)plt.axis('off')plt.title('original')plt.imshow(image[:,:,[2,1,0]])plt.subplot(122)plt.axis('off')plt.title('edges')plt.imshow(edges, cmap='gray')plt.tight_layout()plt.show()

Get OpenCV 3 Computer Vision with Python Cookbook 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.