Permalink
Browse files

dempster shaffer stuff working now, but better as a single bar

  • Loading branch information...
jonnyhuck committed Jul 20, 2017
1 parent 16623d6 commit 5186cc599ef3a066ad23174a86f31d3d7366cfc4
Showing with 17 additions and 46 deletions.
  1. +17 −46 dempster.py
  2. BIN out.png
  3. BIN out2.png
@@ -41,59 +41,30 @@
boundingBoxes = [cv2.boundingRect(c) for c in questionCnts]
(contours, boundingBoxes) = zip(*sorted(zip(questionCnts, boundingBoxes), key=lambda b:b[1][0], reverse=False))
print len(contours)
# switch back to BGR and draw contours
crop_img = cv2.cvtColor(crop_img,cv2.COLOR_GRAY2BGR)
cv2.drawContours(crop_img, questionCnts, -1, (0,255,0), 2)
# show the result
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)
'''
HERE
# confidence
ds_mass = 0
# loop over the sorted contours
for (j, c) in enumerate(cnts):
for c in contours:
# construct a mask that reveals only the current "bubble" for the question
mask = np.zeros(thresh.shape, dtype="uint8")
cv2.drawContours(mask, [c], -1, 255, -1)
before = cv2.countNonZero(mask)
# apply the mask to the thresholded image, then
# count the number of non-zero pixels in the
# bubble area
# apply the mask to the thresholded image, then count the number of non-zero pixels in the bubble area
mask = cv2.bitwise_and(thresh, thresh, mask=mask)
total = cv2.countNonZero(mask)
# if the current total has a larger number of total
# non-zero pixels, then we are examining the currently
# bubbled-in answer
if bubbled is None or total > bubbled[0]:
bubbled = (total, j)
# initialize the contour color and the index of the
# *correct* answer
color = (0, 0, 255)
k = ANSWER_KEY[q]
after = cv2.countNonZero(mask)
# check to see if the bubbled answer is correct
if k == bubbled[1]:
color = (0, 255, 0)
correct += 1
# draw the outline of the correct answer on the test
cv2.drawContours(paper, [cnts[k]], -1, color, 3)
# get a mass value
ds_mass += after / before
# grab the test taker
score = (correct / 5.0) * 100
print("[INFO] score: {:.2f}%".format(score))
cv2.putText(paper, "{:.2f}%".format(score), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
cv2.imshow("Original", image)
cv2.imshow("Exam", paper)
cv2.waitKey(0)
print "I can see", len(contours), "bubbles, with a mass of", ds_mass
'''
# switch back to BGR and draw contours
crop_img = cv2.cvtColor(crop_img,cv2.COLOR_GRAY2BGR)
cv2.drawContours(crop_img, questionCnts, -1, (0,255,0), 2)
# show the result
# cv2.imshow("cropped", crop_img)
# cv2.waitKey(0)
BIN +23 Bytes (100%) out.png
Binary file not shown.
BIN +690 KB out2.png
Binary file not shown.

0 comments on commit 5186cc5

Please sign in to comment.