Ask Your Question

completing characters to get their contour

asked 2017-10-10 04:20:55 -0500

Finch gravatar image

Hi guys, at the moment I am working on OCR using opencv in c++. After processing my image I get something like this:

image description

The problem is that the pixels of the display have a big distance between each other so filtering results in not fully connected characters. I tried to play with dilate but it makes the characters way too big. Do you have an idea how to solve my problem?

I thought about writing my own little algorythm which connects contours (or their moments) if the distance between them is at a certain length but I am pretty sure there is an easier way which I just didn't think of yet.


edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2017-10-11 21:15:59 -0500

Ziri gravatar image

If using Opencv OCR is not necessary try training your images so you don't need to preprocess.

edit flag offensive delete link more


Test answer

mshabunin gravatar imagemshabunin ( 2017-10-12 08:22:28 -0500 )edit

test comment

Finch_the_second gravatar imageFinch_the_second ( 2017-10-12 08:47:57 -0500 )edit

answered 2017-10-10 07:23:50 -0500

LBerger gravatar image

Yes using closing or openning does not solve your problem.

You can try connectedComponentsWithStat and use gravity center to look for nearest neighbours. Then you can can fixed a distance threshold to connect components.

edit flag offensive delete link more

answered 2017-10-11 06:53:06 -0500

updated 2017-10-11 06:56:06 -0500

Wait wait wait. if you first dilate until connection and then apply equal iterations of erosion again, you will have a perfect fixed result right? Try the inbrowser javascript sample and be amazed about the possibilities.

And even if the erosion part destroys the connection again, after dilation you can always apply the thinning operators.

edit flag offensive delete link more


Alright, for some reason my other acc doesn't work so I created this one. The erosion/dilation works pretty good for "unique" character but characters like "1" "I" "i" "l" are really hard to distinguish because dilate/erode are smoothing the endges too much.

I will try the thinning and also will try to adjust some parameters, maybe I get a satisfying result.

Finch_the_second gravatar imageFinch_the_second ( 2017-10-13 04:29:27 -0500 )edit

Well covering i, l and 1 is the worst case for any OCR application and also the most challenging ones...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-13 07:00:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-10 04:20:55 -0500

Seen: 108 times

Last updated: Oct 12