Image segmentation
Segmentation is a process of partitioning images into different regions. Contours are lines or curves around the boundary of an object. Image segmentation using contours is discussed in this section.
How to do it...
- Import the Computer Vision package -
cv2
:
import cv2 # Import Numerical Python package - numpy as np import numpy as np
- Read the image using the built-in
imread
function:
image = cv2.imread('image_5.jpg')
- Display the original image using the built-in
imshow
function:
cv2.imshow("Original", image)
- Wait until any key is pressed:
cv2.waitKey(0)
- 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)
- Display the edge detected output image using the built-in
imshow
function:
cv2.imshow("Canny Edge Detection", canny)
- Wait until any key is pressed:
cv2.waitKey(0)
- Execute the contour detection system:
# cv2.findContours is the built-in function to find...