OCR fast and reliable... is it possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

OCR fast and reliable... is it possible?

27 Mar 2022, 07:23

Hello there.

I have .png Images like the one in the attachement. Sometimes the background has a greyscale image on it. Th color of the characters is always the same.

I would like to extract the information written on them. I tried
- Vis2.1 viewtopic.php?t=36047
- Capture2Text viewtopic.php?t=68241
- UWP built into Windows viewtopic.php?t=72674

They all "kinda work". UWP is the fastest by far and would be my favorite, but...
the recognition is not reliable for all of them, not at all. Sometimes a "1" is a "i", some words get omitted all the way... it's no good to me like that. I need 99.9% recognition reliability.

Is there any way I can achieve that? Maybe define what the font or the font size are (because that never changes) or anything? Or a dicitionary that can be linked to the recognition (becauser there are not many words on the picture)

any ideas appreciated. Thanks in advance. Simon
Attachments
image.png
image.png (2.64 KiB) Viewed 2239 times
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: OCR fast and reliable... is it possible?

27 Mar 2022, 07:46

There are techniques that can help greatly. For the cases where there is just one extra color in the background like the gray vertical bars, you can replace them with black before performing the OCR with @Xtra’s Gdip_FilterColor(). Because it uses MCode (a compiled C function), it is very fast.

For the case where you have an image in the background (and maybe you just use this for all cases), you could use his variant of that function called Gdip_ColorFilter(), which replaces all but the target color, and you could replace everything but the color of the text with black. This would work since it looks like your text is made up of one pure color, not shades of colors to smooth the edges.

To maximize your success, since OCR routines typically perform better with black text on a white background, I suggest you you use Gdip_ColorFilter() twice. First, replace everything that’s not the text color with white, then use it again to replace everything that’s not white with black. The result will be black text on a white background with no surrounding clutter.
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

Re: OCR fast and reliable... is it possible?

27 Mar 2022, 14:31

Hello Boiler. Thanks for your reply!!

I tried Xtra's Gdip_ColorFilter, which works nicely. But the recognition stays the same. Both the original and the filtered image (black on white background) produce

26.03.2022 03:11
Serie 4 Bild 4
4.00 mm
512x62B

when using UWP-API - it should read 628 at the end, not 62B.

Is there anything I can do besides optimizing the source image? The resolution will usually be better, but sometimes I need OCR to be reliable also at the resolution of the examples.

Thanks in advance
Attachments
example2.PNG
example2.PNG (2.65 KiB) Viewed 2120 times
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: OCR fast and reliable... is it possible?

27 Mar 2022, 15:46

Well, you did a good job implementing that function. That’s too bad that the OCR still mixes up characters like that.

Since the characters are so repeatable, I was going to say that I could write a 100% accurate homegrown OCR routine based on ImageSearch, which I’ve done before for numeric characters. You would just need a reference image of each possible character. It would also take some extra effort to reproduce the spaces in all the right places, but it could be done. One way that would be relatively easy to handle the spaces would be to let the OCR routine do its thing, then replace each of the non-space characters with the ones found by my routine. I’m not sure that’s a path you want to go down, but it’s possible.
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

Re: OCR fast and reliable... is it possible?

27 Mar 2022, 16:21

Hmm. The OCR really needs to be snappy, i'd say less than 1 second.

There are always the same words on the image, e.g. "Serie" or "Bild". I acutally need the numbers after those words, very reliably. Not sure how ImageSearch can help here. But maybe you can elaborate a bit...

Thanks!
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: OCR fast and reliable... is it possible?

27 Mar 2022, 17:11

Well. that’s even easier with ImageSearch. It can easily find the whole word Serie than determine which number follows it, then do the same for Bild and the number that follows it, especially if they’re only followed by single-digit numbers. I have everything I need to write that quickly except examples of the numbers 7 and 9 since they don’t appear in your sample image.
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: OCR fast and reliable... is it possible?

01 Sep 2022, 14:40

@Spitzi: Try to OCR this image derivation:
Attachments
Image_x_8_smooth.zip
(151.42 KiB) Downloaded 76 times
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: OCR fast and reliable... is it possible?

02 Sep 2022, 13:56

I cant even OCR this captcha.
[Mod edit: Link removed.]
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: OCR fast and reliable... is it possible?

02 Sep 2022, 20:40

murataygun wrote:
02 Sep 2022, 13:56
I cant even OCR this captcha.
Our forum doesn't support circumventing captchas. Please refrain from discussing it. Thank you!
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: OCR fast and reliable... is it possible?

05 Sep 2022, 09:53

Thank you. I just wanted that i cant even OCR that simple image. Its nothing about solving captchas.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 351 guests