Insolence Posted January 13, 2005 Share Posted January 13, 2005 (edited) Here's the Au3 script:expandcollapse popup;=========================================================================== ; Setting Opt's ;=========================================================================== Opt("MustDeclareVars", 1) ;=========================================================================== ; Setting hotkeys ;=========================================================================== HotKeySet("{SPACE}", "end") ;=========================================================================== ; Testing OCR ;=========================================================================== Local $Find, $i, $var, $e, $distx, $disty, $File, $String, $DistanceString WinActivate("diablo ii in game.bmp") Sleep(1000) ; Basically this function seperates every character in the ; line into a square $Find = GetCharacters ( 143, 45, 235, 56, 12895428 ) $File = FileOpen( "characters.txt", 1 ) ; This is the word it's reading and it's split into an array. ; It is used to write each letters 'Unique String' to a file ; The unique string is the distances of characters from the ; start point of the top left coordinate $String = StringSplit("ShortStaff", "") For $i = 1 to $Find[0][0] ; Finds every pixel in the square $var = _GetAllPixels($Find[$i][0], $Find[$i][1], $Find[$i][2], $Find[$i][3], 12895428) ; Dim'ing an array the size of the pixels found to record each value Dim $DistanceString[$Var[0][0]] ; For every value, write the distance from StartX/StartY to ; FoundX/FoundY of each pixel For $e = 1 to $Var[0][0] $distx = $Find[$i][0] - $Var[$e][0] $disty = $Find[$i][1] - $Var[$e][1] ; Making one big long string for the letter $DistanceString[$i] = $DistanceString[$i] & $distx & "," & $disty & ";" Next ; For some strange reason there was a 0 at the beggining of each string; ; this gets rid of it. $DistanceString[$i] = StringTrimLeft ( $DistanceString[$i], 1 ) If $i > 1 AND $Find[$i][0]-$Find[$i-1][0] > 10 Then ; Found a space inbetween letters ; FileWriteLine( $File, MsgBox("","", $DistanceReturn[$i])) Else FileWriteLine( $File, $String[$i] & "=" & $DistanceString[$i]) EndIf Next FileClose($File) ;=========================================================================== ; Functions ;=========================================================================== Func _GetAllPixels($StartX, $StartY, $EndX, $EndY, $Color) Local $aCoord, $Length, $Width, $Area,_ $i, $x, $y, $CurrentElement = 1 ; Get area of rectangle to initiate array $Length = Abs($StartX - $EndX) $Width = Abs($StartY - $EndY) $Area = $Length * $Width Dim $aReturn[$Area + 1][2] ; Search inside rectangle for the pixel For $x = $StartX to $EndX For $y = $StartY to $EndY If PixelGetColor( $x, $y) = $Color Then $aReturn[$CurrentElement][0] = $x $aReturn[$CurrentElement][1] = $y $CurrentElement = $CurrentElement + 1 EndIf Next Next ReDim $aReturn[$CurrentElement][2] $aReturn[0][0] = $CurrentElement - 1 Return $aReturn EndFunc Func GetCharacters($StartX, $StartY, $EndX, $EndY, $Color, $Height = 11, $Width = 8) Local $vSearchCoord, $vCharacter = 2, $vLineCheck Dim $vCharCheck, $aNewCharacter[255][4] $vSearchCoord = PixelSearch ($StartX, $StartY, $EndX, $EndY, $Color) $aNewCharacter[1][0] = $vSearchCoord[0] $aNewCharacter[1][1] = $vSearchCoord[1] ;Check for a line between characters to differ between them While $vSearchCoord[0] < $EndX OR $aNewCharacter[$vCharacter][0] $vSearchCoord[0] = $vSearchCoord[0] + 1 $vLineCheck = PixelSearch ($vSearchCoord[0], $vSearchCoord[1], $vSearchCoord[0], $vSearchCoord[1]+$Height, $Color) ; Nothing found: ; Adding end of character coord ; Finding next character within $Height x $Width pixels If @error = 1 Then $vLineCheck = PixelSearch ($vSearchCoord[0], $vSearchCoord[1], $vSearchCoord[0]+$Width, $vSearchCoord[1]+$Height, $Color) $aNewCharacter[$vCharacter-1][2] = $vSearchCoord[0] $aNewCharacter[$vCharacter-1][3] = $vSearchCoord[1]+$Height ; If something is found, add it If @error = 0 Then $vSearchCoord[0] = $vLineCheck[0] $aNewCharacter[$vCharacter][0] = $vLineCheck[0] $aNewCharacter[$vCharacter][1] = $vLineCheck[1] $vCharacter = $vCharacter + 1 EndIf EndIf WEnd $aNewCharacter[0][0] = $vCharacter - 1 ReDim $aNewCharacter[$vCharacter][5] Return $aNewCharacter EndFunc Func End() Exit EndFuncand here's the picture: http://insolence9.com/images/diablo%20ii%20in%20game.bmpIt's kinda sloppy and stuff, but there are a few things I've tried that are commented out. It gets stuck on the letter 'a' in Short Staff and for some reason it only gets to 5 pixels out of the entire letter (should be 13)... probably something in the For loop.If anyone wants a nice challenge this would be it (I assume), I've already got most of the work done. Just need to make the hash tables and split between lines.EDIT : Commented the hell out of it , if you need any more help understanding please let me know. Thanks for the help fellas. Edited February 6, 2005 by Insolence "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Insolence Posted February 6, 2005 Author Share Posted February 6, 2005 Agh cmon people, I can't figure out the problem. "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Lazycat Posted February 6, 2005 Share Posted February 6, 2005 I don't know what viewer you use and can't get script work. Better if you modify script in way, that you bmp will open with the internal GUI functions and it at least will be basically working. It's not so easy inderstand this without any comments. This should be interesting, but probably people just lazy to try understand and get to work this semi-finished code... But you brave man, you try to work with such font... I personally interesting this because I made similar script before, but I'm not went beyond regular SansSerif font. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
zcoacoaz Posted February 6, 2005 Share Posted February 6, 2005 probably because the all the stuff is transparent so it wont be exactly the same every time and wont work the best, maybe you could somehow check it with multiple pictures of the same thing [font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font] Link to comment Share on other sites More sharing options...
Insolence Posted February 6, 2005 Author Share Posted February 6, 2005 Open it up in paint, sorry. I'll comment the hell out of it because it works fairly well... tjis method works, there's just one thing I messed up on somewhere and I cannot find it. "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Insolence Posted February 7, 2005 Author Share Posted February 7, 2005 Bump* "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Lazycat Posted February 7, 2005 Share Posted February 7, 2005 I'm tried to look it and found strange thing: you have Dim $DistanceString[$Var[0][0]] at line 40, it's bound set by $Var[0][0]. In the next loop you wrote $DistanceString[$i] when $i - is not same range as $Var[0][0]. I changed this part of script, as I understand you idea. $String = StringSplit("ShortStaff", "") Dim $DistanceString[$Find[0][0]+1] For $i = 1 to $Find[0][0] ; Finds every pixel in the square $var = _GetAllPixels($Find[$i][0], $Find[$i][1], $Find[$i][2], $Find[$i][3], 12895428) ; Dim'ing an array the size of the pixels found to record each value ; Dim $DistanceString[$Var[0][0]] ; For every value, write the distance from StartX/StartY to ; FoundX/FoundY of each pixel For $e = 1 to $Var[0][0] $distx = $Find[$i][0] - $Var[$e][0] $disty = $Find[$i][1] - $Var[$e][1] ; Making one big long string for the letter $DistanceString[$i] = $DistanceString[$i] & $distx & "," & $disty & ";" Next ; For some strange reason there was a 0 at the beggining of each string; ; this gets rid of it. $DistanceString[$i] = StringTrimLeft ( $DistanceString[$i], 1 ) If $i > 1 AND $Find[$i][0]-$Find[$i-1][0] > 10 Then ; Found a space inbetween letters ; FileWriteLine( $File, MsgBox("","", $DistanceReturn[$i])) Else FileWriteLine( $File, $String[$i] & "=" & $DistanceString[$i]) EndIf Next FileClose($File) Zero at beginning each string is in cause of way of arrays initialization - array contain numeric 0. BTW, very interesting idea about "teaching"... Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
Insolence Posted February 7, 2005 Author Share Posted February 7, 2005 (edited) Thanks Also, thanks a lot for helping. I worked on it for about 5 hours and I couldn't figure out that damned error. Tomorrow I hope we can finish it EDIT: Wait... DID YOU FIX IT!? IS it done?!?! !!!! I gotta go to bed, can't really test it... Edited February 7, 2005 by Insolence "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. 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