Sign in to follow this  
Followers 0
GoofyGremlin

OCR Optimization

3 posts in this topic

I am using OCR for a bot I am writing and have run into a wall. The OCR simply takes to long to run. The speed varies highly, even when reading the same text, between 5 phrases (the bot is meant to read card names which have one or more words) per second to 10 phrases per second. Ideally the bot needs to be closer to 50 a second. I guess my first question would be whether or not this is a realistic goal.

The script I am using works as follows:

One function figures out each individual character. Since the characters are variable width, it starts at bottom left pixel of a row of text and searches each pixel vertically using PixelGetColor(). It stores the pixels that are the right color as 1's in an otherwise empty 2D array. It recognizes the end of a character when it searches an entire column and doesn't find a pixel.

The function then converts the array to a string and uses a switch/case statement to assign the actually character. For example:

$charCapA = "11|111|1111|11|1111|111|11||||||||"

Case $charCapA
        $char = "A"

Then a master function that loops the character functions combines all the characters into the words and phrases, as well as recognizes spaces and the end of the phrase.

Any ideas on making this process faster?

Share this post


Link to post
Share on other sites



REALLY hard to say without looking at your code. The speed of these calculations is highly dependent on your computer processing speed and your code efficiency. However without actually seeing your script one of the ways I cheated doing and OCR in college was to do a pixelchecksum event. This only works if you are using 1 type of font (which it looks like you are doing) but it greatly eliminates many of the calculations. Effectively you determine your matrix using a similar method and than you check the sum of that small area and if you are using a consistent font each letter will have a set and consistent value. Now some of them may be duplicates in which case you than use your function to determine further however this should greatly increase your script speed.

Other than that I cant really say without looking at your script.

GL :-)

Share this post


Link to post
Share on other sites

How can I do a checksum without knowing the area of the letters? (i.e. an 'a' is more pixels wide than an 'i', the next character begins 2 pixels over from the end of the previous character) Wouldn't the next character bleed into my checksum and confuse my OCR?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0