import cv2 as cv 
import numpy as np
def areaFinder(contours):
    areas = []
    for c in contours:
        a =cv.contourArea(c)
        areas.append(a)
    return areas
def sortedContoursByArea(img, larger_to_smaller=True):
    edges_img = cv.Canny(img, 100, 150)
    contours , h = cv.findContours(edges_img, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)   
    sorted_contours = sorted(contours, key=cv.contourArea, reverse=larger_to_smaller)
    return sorted_contours
img = cv.imread('./Images/sample-image.png')
sorted_contours = sortedContoursByArea(img, larger_to_smaller=True)
# print(areaFinder(contours))
print(areaFinder(sorted_contours))
for c in sorted_contours:
    cv.drawContours(img, c,  -1, 244, 3)
    cv.imshow('img', img)
    cv.waitKey(0)
cv.destroyAllWindows()
[((14, 6, 14, 44), 'cv2.imread', 'cv.imread', ({(14, 16, 14, 43): '"""./Images/sample-image.png"""'}, {}), "('./Images/sample-image.png')", True, 'import cv2 as cv\n'), ((22, 0, 22, 22), 'cv2.destroyAllWindows', 'cv.destroyAllWindows', ({}, {}), '()', True, 'import cv2 as cv\n'), ((10, 16, 10, 39), 'cv2.Canny', 'cv.Canny', ({(10, 25, 10, 28): 'img', (10, 30, 10, 33): '100', (10, 35, 10, 38): '150'}, {}), '(img, 100, 150)', True, 'import cv2 as cv\n'), ((11, 19, 11, 85), 'cv2.findContours', 'cv.findContours', ({(11, 35, 11, 44): 'edges_img', (11, 46, 11, 62): 'cv.RETR_EXTERNAL', (11, 64, 11, 84): 'cv.CHAIN_APPROX_NONE'}, {}), '(edges_img, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)', True, 'import cv2 as cv\n'), ((19, 4, 19, 40), 'cv2.drawContours', 'cv.drawContours', ({(19, 20, 19, 23): 'img', (19, 25, 19, 26): 'c', (19, 29, 19, 31): '(-1)', (19, 33, 19, 36): '(244)', (19, 38, 19, 39): '(3)'}, {}), '(img, c, -1, 244, 3)', True, 'import cv2 as cv\n'), ((20, 4, 20, 25), 'cv2.imshow', 'cv.imshow', ({(20, 14, 20, 19): '"""img"""', (20, 21, 20, 24): 'img'}, {}), "('img', img)", True, 'import cv2 as cv\n'), ((21, 4, 21, 17), 'cv2.waitKey', 'cv.waitKey', ({(21, 15, 21, 16): '(0)'}, {}), '(0)', True, 'import cv2 as cv\n'), ((6, 11, 6, 28), 'cv2.contourArea', 'cv.contourArea', ({(6, 26, 6, 27): 'c'}, {}), '(c)', True, 'import cv2 as cv\n')]