I have a binary image (binary_image_full_sizes.png) and I would like to find the large oval contour in the middle. The cv2.findContours() function does not return the contour I’m looking for but when I scale the image by 1/2, it finds the contour. How can I make it find the contour for the full size image?
inverted_binary_image = cv2.imread('binary_image_full_scale.png')
white_pixels = np.sum(inverted_binary_image == 255)
# # Find Canny edges
edged = cv2.Canny(inverted_binary_image, 30, 200)
# Finding Contours
# Use a copy of the image e.g. edged.copy()
# since findContours alters the image
contours, _ = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
min_area = white_pixels / 10
filtered_contours = [cnt for cnt in contours if cv2.contourArea(cnt) > min_area]
# Convert inverted_binary_image to a color image
inverted_binary_image = cv2.cvtColor(inverted_binary_image, cv2.COLOR_GRAY2BGR)
cv2.drawContours(inverted_binary_image, filtered_contours, 0, (0, 255, 0), 3)
# Save the image with drawn contours
contour_image_path = 'binary_image_with_countours_half_scaled.png'
cv2.imwrite(contour_image_path, inverted_binary_image)