The Cv2 find contour won’t identify circles which are a little bit incomplete?

Hello,

I made my own home-made little “multi-choice bubble sheet marking program”

It finds circles in a line on a page and identifies the circle which has been filled in.

Yesterday, I printed a couple of sheets on my Epson L350 inkjet printer, just to test a quiz. A couple of the jets must have been blocked.

Around question 23, the circles were a little incomplete in a line across the page, corresponding with the bottom of the circles in that row.

My program fails then, because it must count the number of circles on the page first, to know which row it is dealing with. For example, if every row has 4 choices, A, B, C, D, then the program checks the contours in batches of 4.

The program knows how many contours there must be from the .csv Answer Key file.

This finds the contours:

# find contours in the thresholded image, then initialize
    # the list of contours that correspond to questions
    thresh2 = thresh.copy()
    contours2, hierarchy = cv2.findContours(thresh2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

Is there some way to catch these “almost complete circles”??

I also filter out contours that I don’t want, but allow “blobs” with this because students often go over the edges of the circles:

Q_contours = []
    # loop over the contours
    for c in contours2:
        # compute the bounding box of the contour, then use the
        # bounding box to derive the aspect ratio
        (x, y, w, h) = cv2.boundingRect(c)        
        ar = w / float(h)
        # in order to label the contour as a question, region
        # should be sufficiently wide, sufficiently tall, and
        # have an aspect ratio approximately equal to 1        
        # basically accept blobs. Should reduce the amount of rejects to a minimum
        if w > 30 and h > 30 and w < 65 and h < 65:
            Q_contours.append(c)

Normally, my little program does a good job, when the printing is OK.

thanks
jackyjoy

wrong approach, I’d say.

post some pictures please. you might want to use an image pastebin since this forum has some limits on newbies.