0

The goal: to have it possible for a software library, such as Tesseract, be able to read the work TMP HW from the picture below.

I'm trying to find ways to "connect the dots", so to speak, using OpenCV, but I'm not sure it's possible. I have pictures with dotted text in different colors like below, which I then transform into a Grey scale picture and then apply canny to find edges. I've tried something with blurring, canny, erosion and dilation, but alas, being a newbie with this stuff, it looks like I don't seem to find a way to make these letters "whole" with edges.

Though it seems to be using OpenCV it's possible to create quite recognizable letters and not that much "noise" (and I think, if it matters, can find a way to correct the orientation too), somehow creating edges between the dots to make OCR libraries work better seem to elude. Any tips?

For the reference, I found How to connect broken lines in a binary image using Python/Opencv and Canny Edge Image - Noise removal for instance.

<Edit: language chosen, though examples etc. in any language probably go. I'm likely to work on .NET if it matters.

Original 1 transformed with grey scale and canny.

Original 1. Slightly wrinkled example. Most difficult one.

Veksi
  • 3,556
  • 3
  • 30
  • 69
  • 1
    are the 'dots' guaranteed to be regularly spaced ? if yes, you could extract the dots, least-square-fit an affine xform and get a lower resolution image (mapping dots to pixel) to be passed to the ocr engine ... – Massimiliano Janes Nov 20 '17 at 12:25
  • There is some variation, but pushing grey scale images through canny seem to produce images comparable to that shown, so I'd be inclined to say 'yes' for the purposes of this question. I have to examine what you wrote (being newbie and all) and get back with the results. – Veksi Nov 20 '17 at 12:34
  • Can you show the original image? Or a few of them? And choose a language, please – Miki Nov 20 '17 at 12:38
  • Miki, I added one original picture. The ones I'm learning to use these libraries are mostly like that. The color can be black or blue too, there can be a bit more less specs, the letters can be a bit clearer or a bit smudgier, the paper can be stretched or wrinkled a bit (skews the letters, but only little). In some cases overlap a bit, but I suppose not the purpose of this question and I think I'm not that interested on that since it'd imply neural network or somesuch). – Veksi Nov 20 '17 at 12:44
  • @Miki I added some more pictures. The third one has the most noise and wrinkles in my sample set. – Veksi Nov 20 '17 at 12:50
  • 1
    if the letters are never too 'sparse', another idea could be to binarize the image and calculate its DFT; from there, you could estimate both the orientation and the avarage dot radius ( ~1/(3 *dot peak frequency) ); then, you'd just rotate and down-sample ... – Massimiliano Janes Nov 20 '17 at 14:16
  • 1
    Threshed the gray image, do morph-open and morph-dilate. You should make sure the space width(height) is in a suitable range. I added my answer. – Kinght 金 Nov 20 '17 at 14:50

1 Answers1

5

Threshed the gray image, do morph-open and morph-dilate.

You should make sure the space width(height) is in a suitable range.

enter image description here

Kinght 金
  • 17,681
  • 4
  • 60
  • 74
  • Looks good. I think this is is what I need, I'll just figure out how to call the functions on my own. E.g. just checking the syntax quickly, it's aboutish `src.Dilate(new Mat(), new Point(-1, -1), 1);` but different parameters. – Veksi Nov 21 '17 at 05:52