May 2020
Beginner to intermediate
430 pages
10h 39m
English
We first need to import the image and then use the Canny edge detector to find the edges in the image. This works very well as the shape of our object is a circle with a rounded edge. The following is the detailed code required:
threshold =100canny_output = cv2.Canny(img, threshold, threshold * 2)contours, hierarchy = cv2.findContours(canny_output, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
As the preceding code shows, after Canny edge detection, we applied the OpenCV findContours() method. This method has three arguments: