<p>After years working in this theme, I can tell now, that what I wanted to do take a big effort, it's quite slow, and NEVER worked as I expected. The irregularities of the pixels in the characters are always unpredictable, that's why "easy algorithms" don't work. </p>

<p>Question: It's impossible then to have a decent OCR, which can read damaged characters? </p>

<p>Answer: No, it's not impossible. But it takes "a bit" more than just using erosion, morphological closing or something like that. </p>

<p>Then, how? Neural Networks :)</p>

<p>Here are two amazing papers that help me a lot:</p>

<p><a href="https://www.researchgate.net/publication/260341307_Can_we_build_language-independent_OCR_using_LSTM_networks" rel="nofollow noreferrer">Can we build language-independent OCR using LSTM networks?</a></p>

<p><a href="https://arxiv.org/pdf/1506.04395v2.pdf" rel="nofollow noreferrer">Reading Scene Text in Deep Convolutional Sequences</a></p>

<p>And for those who aren't familiar with RNN, I can suggest this: </p>

<p><a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/" rel="nofollow noreferrer">Understanding LSTM Networks</a></p>

<p>There's also a python library, which works pretty good (and unfortunately even better for C++):</p>

<p><a href="https://github.com/tmbdev/ocropy" rel="nofollow noreferrer">ocropy</a></p>

<p>I really hope this can help someone. </p>
Improve the quality of the letters in a image
<p>I'm working with images that have text. The problem is that these images are receipts, and after a lot of transformations, the text lost quality. 
I'm using python and opencv.
I was trying with a lot of combinations of morphological transformations from the doc <a href="http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html" rel="nofollow noreferrer">Morphological Transformations</a>, but I don't get satisfactory results. </p>

<p>I'm doing this right now (I'll comment what I've tried, and just let uncommented what I'm using):</p>

<pre><code>kernel = np.ones((2, 2), np.uint8)
# opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
# closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
# dilation = cv2.dilate(opening, kernel, iterations=1)
# kernel = np.ones((3, 3), np.uint8)
erosion = cv2.erode(img, kernel, iterations=1)
# gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
#
img = erosion.copy()
</code></pre>

<p>With this, from this original image:</p>

<p><a href="https://i.stack.imgur.com/fKJkH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fKJkH.png" alt="enter image description here"></a></p>

<p>I get this:</p>

<p><a href="https://i.stack.imgur.com/Hvmvk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hvmvk.png" alt="enter image description here"></a></p>

<p>It's a little bit better, as you can see. But it still too bad. The OCR (tesseract) doesn't recognize the characters here very well. I've trained, but as you can note, every "e" is different, and so on. </p>

<p>I get good results, but I think, if I resolve this problem, they would be even better. </p>

<p>Maybe I can do another thing, or use a better combination of the morphological transformations. If there is another tool (PIL, imagemagick, etc..) that I could use, I can use it. </p>

<p>Here's the whole image, so you can see how it looks:</p>

<p><a href="https://i.stack.imgur.com/AorH6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AorH6.png" alt="enter image description here"></a></p>

<p>As I said, it's not so bad, but a little be more "optimization" of the letters would be perfect. </p>