mythrex / OMR-Scanner

This project uses open cv to evaluate OMR sheets. We are trying to make this system as reliable as possible.
49 stars 23 forks source link

Sorting contours is not working properly #2

Closed mythrex closed 6 years ago

mythrex commented 6 years ago
# sort the question contours from top to bottom
questionCnts = contours.sort_contours(questionCnts, method='top-to-bottom')[0]
correct = 0
# sort the first 4 countours left to right
e = contours.sort_contours(questionCnts[0:4])[0]
# this should draw 1 a countour
cv2.drawContours(paper, [e[0]], -1, 255, -1)

This code should show question 1 A contour but instead it shows some random contour. See in pic which contour is being displayed. screenshot from 2018-10-09 13-00-27

# sort the question contours from top to bottom
questionCnts = contours.sort_contours(questionCnts, method='top-to-bottom')[0]
correct = 0
# sort the first 4 countours left to right
e = contours.sort_contours(questionCnts[0:4])[0]
# this should draw 1 b countour
cv2.drawContours(paper, [e[1]], -1, 255, -1)

This code should show question 1 B contour but instead it shows some random contour. but instead the following has been showing. screenshot from 2018-10-09 13-01-47

mythrex commented 6 years ago

Found a work around. Instead for sorting top to bottom first. Sort left to right first. This will sort all the countours form left to right such that first contour is 15a and 15th countour is 1a and 16th is 30a. screenshot from 2018-10-09 13-23-55

Then sort from top to bottom

# sort the question contours from left to right
questionCnts = contours.sort_contours(questionCnts)[0]
# sort the first 4 countours left to right
e = contours.sort_contours(questionCnts[0:240], method='top-to-bottom')[0]
cv2.drawContours(paper, questionCnts[0:16], -1, 255, -1)

It works but don't understand fully why? :)

mythrex commented 6 years ago

The problem is not resolved till now. Now the contours are sorted as: 1A-> questionCnts[0] 1B-> questionCnts[1] .. Now here is the twist 16A-> questionCnts[5]

questionCnts[104] will be .. that's right 37A image