How to extract pencil markings from the below sheet using opencv in python

72 views Asked by At

I am unable to extract the pencil markings provided in the below picture using opencv. I am unsure if it's because of the kernel size (though I tried playing with the size), but the extraction is not particular. This is based out of MCQ scanner and the pencil markings act as an ID number for a particular student

The image is this:

Original image

I am using the following code to extract the imge:

# Assume student_area is the image posted above

blur_img = cv2.GaussianBlur(student_area,(5,5),0)
#cv2.imshow("gaussian_blur", blur_img)

res, cut_image = cv2.threshold(blur_img, 160, 255, cv2.THRESH_BINARY_INV)
#cv2.imshow("image", cut_image)

# apply morphology close
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,2))
morph = cv2.morphologyEx(cut_image, cv2.MORPH_CLOSE, kernel)
morph = cv2.morphologyEx(morph, cv2.MORPH_OPEN, (20,10))

and the image I am getting looks like this:

enter image description here

I think that the morphology open is not working as it should have, probably due to the kernel size. Can anyone help me in this please?

Afterwards, I identifying contours and using the cv2.moments() to get the center points.

Thanks

0

There are 0 answers