import cv2
Read the image
img = cv2.imread("image.jpg")
Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Find the contours
contours, _ = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
Iterate through each contour
for cnt in contours: