Jump to content

New OCR Script: Come and get it!


deo
 Share

Recommended Posts

First Off, I was having trouble finding an OCR script on here that could be considered reliable. Most of the OCR's I've seen only counts the width of the characters. The downside of that is that with some fonts, different letters will have the same credentials, therefore rendering the script useless.

I wanted an OCR that would be able to differentiate between all characters, not just based off of a X coord, but a Y coord as well.

Second, I was having trouble getting any help on the subject and thought that this community could use something useful and reliable. So I spent the weekend working on this and have decieded to release this to everyone in hopes that it will help someone else.

Here's how it works:

The script will scan from left to right, and from BOTTOM to Top. The bottom-left pixel for each letter will be given a coord of (0,0) and will scan and detect from there.

Example:

Posted Image

Instead of performing multiple loops and checking arrays, this script check's to see what the character is after it's done scanning a single letter.

In order for this script to work, a "baseline" must be specified. This baseline is the very-bottom pixel of ANY letter of the area you are scanning. This would include lowercase "g", "j", "p", "q", "y", etc. Because it scans from bottom to top, the baseline is the start of the scan. The actual width doesnt matter, as long as its wider than the text you want to scan, but the baseline has to be EXACT. The baseline should equal Y position + Height of area to scan.

This is my first script, so the code might not be as advanced as some of the guru's around here, so feel free to give me feedback on what could make this script better/faster.

The downside of this script is that it only has the ability to read one line of text, it doesnt support multi-line text.

Anyway, download it and try it out. Please let me know what you think.

~Deo

DeoOcr.rar

Edited by deo
Link to comment
Share on other sites

I also want to make mention that with $Debug set to 1, and if the parameters are correct, the script will build a definition's list (in the form of a Switch/Case) for the font specified.

Link to comment
Share on other sites

Shouldn't this be in example scripts?

Link to comment
Share on other sites

  • Moderators

Easy to look through that's for sure... nice work, and I like what you were thinking when you wrote it. I have to say that I'd still like to see a bit different optimization, and arrays in the _CheckChar() function, but all in all, you could actually make this sounder than others for sure.

When I get a bit more time, I'll have a "deeper" look.

Also... Didn't you mean to post this in the scripts and scraps forum? If so, I'm sure a mod will have no problems moving it for you.

Edit:

Ooops, someone already stated the forum... and I even gave it it's old name :whistle: lol.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

When I get a bit more time, I'll have a "deeper" look.

Yes, please do. I'd like to make this as optimized and fast as it can possibly be. Im sure alot of people would appreciate something like this. I sure would have a few days ago :whistle:

Link to comment
Share on other sites

  • Moderators

Yes, please do. I'd like to make this as optimized and fast as it can possibly be. Im sure alot of people would appreciate something like this. I sure would have a few days ago :whistle:

It seems to be font and or size specific. What font and size did you use?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Its a FFF font (http://fontsforflash.com/). If you want to give it a different font, you will need to specify the $CharMaxWidth & $CharMaxHeight, and the base line has to be exact for detection to take place. The area that you're scanning needs to be the height of the font itself.

Link to comment
Share on other sites

  • 4 weeks later...

Hi, im been playing little with your OCR and i like it alot. I put in a little "shade" in it, but havnt been tested enogh. Can you give me a fast curse how the cord system work... i tried to make my own Numbers to it but the OCR dont find it (in the Debug it find the 3 as a B but it doesnt print a B or a 3 )

Edited by Rizzet
Link to comment
Share on other sites

I like your script alot, i have now learned how to use it and im using it in 1 of my scripts. but well with some "fonts" dont know why but it gets messed up and wont work.

Now i found out that its not reseting the Y axel everytime its a new Y line so i made this little change and works fine now

For $tLeft = $Left To (($Width - 1) + $Left)
            $FilledLine = 0
            For $tTop = $BaseLine To $BaseLine - $CharMaxHeight Step -1         
                If Hex(PixelGetColor($tLeft, $tTop), 6) = $CharColor Then
                    If $Debug = 1 Then
                        GUICtrlCreatePic("img\blue.bmp", $tLeft, $tTop+$BaseLine, 1, 1)
                        GUISetState(@SW_SHOW)
                    EndIf
                    ;_msg($X & @CR & $Y)
                    $A &= $X & $Y
                    $FilledLine = 1
                EndIf
                If ($Y < ($Height - 1)) Then
                    $Y += 1
                Else
                    $Y = 0
                EndIf
            Next

$Y = 0 ;<--------------------------------------------------This is the change Now everytime it comes to a new line the Y resets to 0

            If $X <= $CharMaxWidth Then
                ;Check for an empty vertical line
                If $FilledLine = 0 Then
                    If $Debug = 1 Then
                        GUICtrlCreatePic("img\red.bmp", $tLeft, $tTop, 1, 11)
                        GUISetState(@SW_SHOW)
                    EndIf
                
                    If $A <> "" Then
                        ;We found a space between letters, lets check and see what letter we found.
                        $StringReturn &= _CheckChar()
                        $A = ""
                    EndIf
                    $X = 0
                Else
                    $X += 1
                EndIf
            Else
                $X = 0
            EndIf
        Next
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...