Ask Your Question
2

Preprocessing before OCR

asked 2016-05-31 07:56:18 -0600

psychoil gravatar image

Hi all,

I'm pretty new to CV, I'm doing some experiment that requires OCR, I'm ussing tesseract as the OCR Engine.

I have the following image:

image description

I was trying applying all kind of preprocessing techniques but wasn't able to filter all the noise and have only the text.

(I'm interested in ARS, 0 - 1, TOT, 04:02)

My biggest issue is finding a way to filter those texts even though I know their color (the fact that they are gradient makes it even a bigger issue for me)

any tips/ideas on how to tackle this problem?

some example of the image after some processing (which aren't good enough as the tesseract fails with reading it): image description

edit retag flag offensive close merge delete

Comments

3

You can try Stroke Width Transform to get probable location of text: Detecting Text in Natural Scenes with Stroke Width Transform (never tested it). Have you already tried Canny edge detection?

Usually, TV logos are always at the same place. It is a kind of cheat but this should facilitate your work.

Eduardo gravatar imageEduardo ( 2016-05-31 12:15:09 -0600 )edit

Yeah, the fact that I know where the banner is should be helpful and I can cut the desired area the problem is the resolution and the noise.

psychoil gravatar imagepsychoil ( 2016-06-01 13:16:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-06-01 05:22:55 -0600

essamzaky gravatar image

updated 2016-06-02 09:33:02 -0600

You need smart method from text extraction , normal binarization method will not work because there are text with different colors , so you need SWT SWT PDF , SWT Video or read this paper Text detection

Also refer to the following answer Text detection Answer

I found an implementation for SWT i'm not sure if it's correct or not , because there are some thin lines not exist in the original image , Here it's the code link text i used the code in file called SWT.cpp because it needs only OpenCV , there is another implemenation code in the same project in file called "TextDetection.cpp" but it needs another library called BOOST beside OpenCV , i did not try the second code

and here it the result for the code exsit in SWT.CPP :

note: i had multiplied the size by 3

when option text dark on white image description

when the option is text white in dark background image description

i think you can merge the two images and extract the required text

but first you should find the sure correct implementation for SWT

edit flag offensive delete link more

Comments

Hey! Thanks, I have read and tried to use SWT, my biggest problem is to clear the noises from the image and maybe scale it so the letters/numbers will be bigger.

psychoil gravatar imagepsychoil ( 2016-06-01 13:16:10 -0600 )edit
1

@psychoil the passed image is very small , do you resized the original image ? , if the images is resized please upload the original image

essamzaky gravatar imageessamzaky ( 2016-06-02 04:39:46 -0600 )edit

Actually this is the size I have of this content I was thinking about scaling it and making it bigger.

(Of course this is just a part of the whole image, but this is the part I'm intersted in so I simply cut it without resizing.)

psychoil gravatar imagepsychoil ( 2016-06-02 04:41:11 -0600 )edit

I compared the two images you uploaded and i noticed that , the cropped part from original images is resized , please upload the original image without resizing , may be the cropping tool do the resize

essamzaky gravatar imageessamzaky ( 2016-06-02 05:04:15 -0600 )edit

you are right, the second image is after I scaled the original image.

My original image is 960 x 540 but most of it is noise and I want the text only from the portion that I cut from it which includes the text I want to process.

Do you think that scaling up and then applying SWT will help? Im working on it right now

psychoil gravatar imagepsychoil ( 2016-06-02 07:12:43 -0600 )edit

The second image is 748 X 337 the size is smaller than the size of the original 960 X 540 are you scalling down ??? , would you upload the original image not the cropped , anyway i read that SWT not working well when the image is blured or edging will not be sharp and canny will give bad edges.

essamzaky gravatar imageessamzaky ( 2016-06-02 07:35:00 -0600 )edit

Original image is: http://i.imgur.com/e7bTW7r.png, I was cropping the area that contain the text Im interested in.

Basically I think SWT will have problem with the anti-aliasing on the text too. :(

EDIT: I found out that I resized using ImageMagick by 300% before processing it. thats where the different sizes came from.

psychoil gravatar imagepsychoil ( 2016-06-02 07:37:30 -0600 )edit

I found and implementation of SWT , i do not know if it's correct or not , i will post the result images in the answer

essamzaky gravatar imageessamzaky ( 2016-06-02 08:20:18 -0600 )edit

Thanks, do you mind sharing the code you were using? I found a python implemention of SWT but Tesscart wasn't able to get the text from the output neither on the 2 images you showed.

THE SWT I was using for testing is: https://github.com/mypetyak/StrokeWid...

again, thanks a lot !

psychoil gravatar imagepsychoil ( 2016-06-02 09:15:25 -0600 )edit

Ok added the code link in the answer , regarding Tesseract you may need to Train font and use it , i remember that Tesseract does not perform well when character width or or height less than 20 pixel

essamzaky gravatar imageessamzaky ( 2016-06-02 09:36:02 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-05-31 07:56:18 -0600

Seen: 4,921 times

Last updated: Jun 02 '16