<gh_stars>0
def count(filename):
        from PIL import Image
        import cv2
        from PIL import Image

        col = Image.open(filename)
        gray = col.convert('L')
        bw = gray.point(lambda x: 0 if x<128 else 255, '1')
        bw.save(filename)
        import cv2
        gray = cv2.imread(filename, 0)

        ## threshold
        th, threshed = cv2.threshold(gray, 100, 255,cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)

        ## findcontours
        cnts = cv2.findContours(threshed, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]


        ## filter by area
        s1= 3
        s2 = 20
        xcnts = []
        for cnt in cnts:
            if s1<cv2.contourArea(cnt) <s2:
                xcnts.append(cnt)
        add = len(xcnts)

        print(round(int(add/3)))
        add = round(int(add/3))
        return(add)
def count(filename):
        from PIL import Image
        import cv2
        from PIL import Image

        col = Image.open(filename)
        gray = col.convert('L')
        bw = gray.point(lambda x: 0 if x<128 else 255, '1')
        bw.save(filename)
        import cv2
        gray = cv2.imread(filename, 0)

        ## threshold
        th, threshed = cv2.threshold(gray, 100, 255,cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)

        ## findcontours
        cnts = cv2.findContours(threshed, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]


        ## filter by area
        s1= 3
        s2 = 20
        xcnts = []
        for cnt in cnts:
            if s1<cv2.contourArea(cnt) <s2:
                xcnts.append(cnt)
        add = len(xcnts)

        print(round(int(add/3)))
        add = round(int(add/3))
        return(add)
## threshold ## findcontours ## filter by area