How to group two-contour(like i,j,!,?) characters in opencv python?

asked 2017-11-03 10:04:21 -0500

shebna12 gravatar image

updated 2017-11-05 09:09:03 -0500

I'm trying to do the segmentation part of handwriting recognition. So far, my code can correctly identify the characters in an image with handwriting. I want to group the dot from the letters, like i,j,!,?, with its corresponding body. I was thinking of taking note of the next/previous contour's x-value if it's near to the x-value of the current contour but that will just result into false grouping results especially when the dot is drawn very near the next/previous different letter. Anyways, Here is an example of what my code can currently do: dot in letter i separate from body

P.S I am using OpenCV Python 3.3.0 Sadly I cannot attach the code for this because it's very long since it's not well-written code but it's pretty straight forward. From a pre-processed image, I extracted the contours using cv2.findContours function. Then, I drew a rectangle on those contours. Now, I want the dot in the character "i" to be in the same contour as its body.

edit retag flag offensive close merge delete

Comments

What is your specific question? For what version of OpenCV? You say you are working in python, do you have specific code examples you can attach? Please add any improvements to your question above by editing it. i'm not an expert in this area, so I'm unlikely to be able to help out, but I do hope that if you're a little more specific you'll get a better response to your question. I was recently a new community member too.

opalmirror gravatar imageopalmirror ( 2017-11-03 18:52:34 -0500 )edit

Thanks for updating your question. I better understand what you're asking and how far you've gotten. I'm hoping more expert folks feel more encouraged to jump in. Totally guessing here about an approach, though it's out of my expertise: I wonder if there are OpenCV OCR handwriting detection examples that can be brought into play (try a web search), so if the bottom stroke of an i is seen or likely, that you can then have a hint to search for the corresponding top 'dot' stroke, look for it in an expanded reason above the top of the bottom stroke of the i, and then draw a box around both the components.... to render it as a single letter, you may need to mask parts of adjacent characters out of the box.

opalmirror gravatar imageopalmirror ( 2017-11-07 15:36:24 -0500 )edit