I want to extract the number of contours/objects in each image along with its side i-e a function should return [num_contours, total_sides, (sides of individual contours)]
But i'm getting two contours for each shape (outer and inner both).
My function:
def get_contour_details(img):
image = img.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
value, thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
contour_edges = [len(cv2.approxPolyDP(contour, 0.01* cv2.arcLength(contour, True), True)) for contour in contours]
num_contours = len(contours)
total_edges = sum(contour_edges)
return num_contours, total_edges, contour_edges
Expected answer: [2, 8, [4,4]]
Got: [4, 18, [4, 4, 4, 6]]
Use below image for processing:
Any kind of help will be appreciated!





