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()
[((474, 512), 'cv2.imread', 'cv.imread', (['"""./Images/sample-image.png"""'], {}), "('./Images/sample-image.png')\n", (483, 512), True, 'import cv2 as cv\n'), ((757, 779), 'cv2.destroyAllWindows', 'cv.destroyAllWindows', ([], {}), '()\n', (777, 779), True, 'import cv2 as cv\n'), ((242, 265), 'cv2.Canny', 'cv.Canny', (['img', '(100)', '(150)'], {}), '(img, 100, 150)\n', (250, 265), True, 'import cv2 as cv\n'), ((285, 351), 'cv2.findContours', 'cv.findContours', (['edges_img', 'cv.RETR_EXTERNAL', 'cv.CHAIN_APPROX_NONE'], {}), '(edges_img, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)\n', (300, 351), True, 'import cv2 as cv\n'), ((676, 711), 'cv2.drawContours', 'cv.drawContours', (['img', 'c', '(-1)', '(244)', '(3)'], {}), '(img, c, -1, 244, 3)\n', (691, 711), True, 'import cv2 as cv\n'), ((717, 738), 'cv2.imshow', 'cv.imshow', (['"""img"""', 'img'], {}), "('img', img)\n", (726, 738), True, 'import cv2 as cv\n'), ((743, 756), 'cv2.waitKey', 'cv.waitKey', (['(0)'], {}), '(0)\n', (753, 756), True, 'import cv2 as cv\n'), ((112, 129), 'cv2.contourArea', 'cv.contourArea', (['c'], {}), '(c)\n', (126, 129), True, 'import cv2 as cv\n')]