I am working on optical mark recognition problem. I found Region of Interest(ROI) where student's roll number to be filled.Which approach can help me to decode filled circle value? i tried to code but it's not functioning properly.
Images
In this image initial ROI is given.After that i have applied segmentation.Third image is filled by student which indicate student's roll number.
this image detect 381 circle but actual circle are 100
Input: Filled circle image
Output: roll number : 4216789503
image = cv2.imread("rotatedb/ROI_omr.png")
hsvimg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_blue = np.array([0,70,0])
upper_blue = np.array([255,255,255])
mask = cv2.inRange(hsvimg, lower_blue, upper_blue)
contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
print "No. of circles",len(contours)
i=0
for contour in contours:
(x,y),radius = cv2.minEnclosingCircle(contour)
center = (int(x),int(y))
radius = int(radius)
cv2.circle(image,center,radius,(0,255,0),2)
position = (center[0] - 10, center[1] + 10)
text_color = (0, 0, 255)
cv2.putText(image, str(i + 1), position, cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
i=i+1
cv2.imshow("thresold",image)
cv2.waitKey(0)
cv2.destroyAllWindows()
As the Markers are in black color, So you should try to segment the black colored segments in the input image, and from that binary mask you may find the contours and filter out the circular shaped contours (you may also want to filter contours with area if you like to).
After finding all the contours, sort the contours as per their
x
coordinate of bounding rect, which would yield us the order of contours as we are traversing them in horizontal direction(cv2.findContours()
returns contours in random order, so it is always a good idea to sort them as per your needs.)Finally you calculate the mid point of each contour and estimate the circle on which they lie.
Code:
Output: