GoofyGremlin Posted July 28, 2009 Share Posted July 28, 2009 Working on OCR for a bot I am making. Reading individual characters works fine and is handled by GetChar(). The problem I am encountering is spaces. Spaces in the font I am reading are a variable number of pixels. I can get the OCR function to recognize spaces, but then it does not realize when it is at the end of the word and endlessly adds spaces. Here is the problem section of my script: Func GetCardName() Do GetChar() If $char = "" Then For $xdum = 0 to 10 For $ydum = 0 To 15 $pixCol = PixelGetColor($xstart + $xdum, $ystart - $ydum) If $pixCol = 0xEBE2AF Then If $space = False Then $char = " " $xstart = $xstart + $xdum $space = True ExitLoop(2) Else $wcomplete = True Msgbox(0, "Complete", "Cardname Complete") ExitLoop(2) EndIf EndIf Next Next Else $space = False EndIf $wordString = $wordString & $char MsgBox(0, "Reading", $wordString) Until $wcomplete = True EndFunc The method I used here was that when GetChar() encounter blank space after a character, it would search the next 10 pixels (bigger than spaces which are 5-9 pixels) to the right for another character. This works find as far as recognizing spaces and restarting on the next character, but never realizes its at the end of the word ($wcomplete never becomes true). I have considered a couple problems I might be having, and would appreciate any comments or ideas. 1. I have been staring at the computer screen for way too long and can't see the obvious mistake. 2. I have some flawed logic in the loop. 3. I am overstepping the end of the column while looking to see if there are extra spaces. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2009 Moderators Share Posted July 28, 2009 GoofyGremlin,This is my attempt to cretae a logical function for you, but of course it is untested. I have tried to simplify it as much as possible and commented almost every line to explain my thinking. Try it and see! >_< expandcollapse popupFunc GetCardName() While 1 ; Try and read character GetChar() ; Assume that $xstart and $ystart are reset for next read if successful ; Was a character read? If $char = "" Then ; No - we have a gap ; Is it a space (5-9 pixels wide) or the end of word (10 pixels wide) For $xdum = 0 to 10 For $ydum = 0 To 15 ; Search the gap $pixCol = PixelGetColor($xstart + $xdum, $ystart - $ydum) ; If we find "text colour" exit the search If $pixCol = 0xEBE2AF Then ExitLoop 2 ; Break out of 2 For...Next loops ; <<<<<<<<<<<<< Use correct syntax for ExitLoop !!!!!! >>>>>>>>>>>>>>>>>>> Next Next ; Check to see if we exited early because text colour was found If $xdum = 11 Then ; No early exit so gap is end of word Msgbox(0, "Complete", "Cardname Complete") ExitLoop ; Break out of While...WEnd loop Else ; Early exit so gap must only be a space $char = " " ; Reset $xstart for next read $xstart = $xstart + $xdum ; Might be $xdum +/- 1 - you will have to test! EndIf EndIf ; Add char to string $wordString = $wordString & $char MsgBox(0, "Reading", $wordString) WEnd EndFuncTwo points - both made in the comments but reiterated here:1. You were using the wrong syntax for ExitLoop - that may have caused your problem in part.2. You will have to play with resetting $xstart after finding a space - I think I have it set correctly, but it might well be a pixel out either way.Let me know how you get on.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
GoofyGremlin Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks a lot that worked. I still don't understand why my original code didn't work thought. Exit 2 and Exit(2) both had the same effect (the help file seems to imply that it has to be in parantheses). But anyway thanks a lot for your help, OCR is now working great. Link to comment Share on other sites More sharing options...
bo8ster Posted July 29, 2009 Share Posted July 29, 2009 Exit and ExitLoop are different. You cannot use ExitLoop like you can Exit. ExitLoop(2) is the incorrect syntax. See http://www.autoitscript.com/autoit3/docs/keywords/ExitLoop.htm. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 29, 2009 Moderators Share Posted July 29, 2009 GoofyGremlin,Your initial code did not work because of several logic errors within it. That is why I went for a complete rewrite rather than amending your code. Sorry, but I am not going to analyse them in detail. As to the syntax question:Exit: "Remarks - The parameter, if included, can be enclosed in parentheses. Thus, the following are equivalent: Exit, Exit 0, and Exit(0). However, Exit() is invalid."ExitLoop: No parentheses allowed.The two are very different in action: Exit quits the script setting a DOS errorlevel (oh, how that takes me back..... >_< ) while ExitLoop breaks out of a While/Do/For loop.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now