How to do it...

  1. Import the Computer Vision package - cv2:
import cv2 
# Import Numerical Python package - numpy as np 
import numpy as np 
  1. Read the image using the built-in imread function:
image = cv2.imread('image_5.jpg') 
  1. Display the original image using the built-in imshow function:
cv2.imshow("Original", image) 
  1. Wait until any key is pressed:
cv2.waitKey(0) 
  1. Execute the Canny edge detection system:
# cv2.Canny is the built-in function used to detect edges 
# cv2.Canny(image, threshold_1, threshold_2) 
canny = cv2.Canny(image, 50, 200) 
  1. Display the edge detected output image using the built-in imshow function:
cv2.imshow("Canny Edge Detection", canny) 
  1. Wait until any key is pressed:
cv2.waitKey(0)
  1. Execute the contour detection ...

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.