Steven Lee Steven Lee - 1 year ago 197
Python Question

Python OpenCV locate characters

In OpenCV 3, is there a way to extract the character "i" as one contour?

This is the image I am working with:

enter image description here

For the character "i" it is recognised as two contours (the dot and the bottom part). However, if I apply

then the characters will merge together. Is there a way to only expand the character "i" so that it can be recognised as one contour?

Answer Source

Try to apply a 'blur' and 'closing' on the image. It should connect the dot in the i

blur = cv2.medianBlur(inputImage,7)

# erosion
kernel = np.ones((11,3),np.uint8)
#kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(10,3))

#erosionKernel = np.ones((3,3), np.uint8)
erosionKernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(10,3))

erosion = cv2.erode(inputImage,erosionKernel,iterations = 1)
closing = cv2.morphologyEx(blur, cv2.MORPH_CLOSE, kernel)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download