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: