In this recipe, we will discover a way of checking whether a point is inside of a contour, or if it belongs to the contour's border.
Checking whether a point is within a contour
Getting ready
You need to have OpenCV 3.x installed, with Python API support.
How to do it...
- Import all of the necessary modules, open an image, and display it on the screen:
import cv2, random
import numpy as np
img = cv2.imread('bw.png', cv2.IMREAD_GRAYSCALE)
- Find the contours of the image and display them:
im2, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2...