Azu Posted September 2, 2006 Share Posted September 2, 2006 Cool, so this will read text and stuff, even if the background is constantly changing, etc? And the letters have slightly different hues? If so I think I might give this a shot. Link to comment Share on other sites More sharing options...
pingpong24 Posted September 2, 2006 Author Share Posted September 2, 2006 stalliont you are totally correct, The best way would be to work out the position of each pixel releating to the entire chareacter, but that would be slow. and AZU this will work on constantly changing background or image etc, long as the chareacter text does not change in colour. however you can add extra coding to recognise hue differences. NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
Azu Posted September 2, 2006 Share Posted September 2, 2006 Cool thanks! Is there a way to make it so if the hue just changes a little, it will still work, besides making a bunch of separate if statements for each one? :S Link to comment Share on other sites More sharing options...
Imtheman Posted September 18, 2006 Share Posted September 18, 2006 Hi I'm totally new to AutoIt. I'm trying to get "NumCR Super Fast EASY NUMBER OCR" to work. But how do I load a picture into the script? What does this mean? $test = _OCR("73", "511", "112", "520") Tnx Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2006 Moderators Share Posted September 18, 2006 Hi I'm totally new to AutoIt.I'm trying to get "NumCR Super Fast EASY NUMBER OCR" to work.But how do I load a picture into the script?What does this mean?$test = _OCR("73", "511", "112", "520")TnxYou might want to start here:http://www.autoitscript.com/forum/index.php?showtopic=21048For a basic understanding of how autoit works, and how to understand function parameters, before tackling something like that.To answer your question, without looking at how the function actually works, I would guess that those numbers are the:Top = X - Start positionLeft = Y - Start positionBottom = X - End positionRight = Y - End positionOf the area in which you want to search.Example of the area:http://www.autoitscript.com/forum/index.ph...st&id=10335 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 More sharing options...
Kickassjoe Posted September 19, 2006 Share Posted September 19, 2006 this is a NICE OCR, easy to use, from what I have seen, haven't tried it yet. The definer is a NICE tool! Thanks for sharing with everyone! What goes around comes around... Payback's a bitch. Link to comment Share on other sites More sharing options...
Imtheman Posted September 19, 2006 Share Posted September 19, 2006 Tnx SmOke_N But I was wondering, how the script know which picture to use? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 19, 2006 Moderators Share Posted September 19, 2006 Tnx SmOke_NBut I was wondering, how the script know which picture to use?By whatever coordinates you use to define the pic. You have to do all the grunt work first. 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 More sharing options...
Imtheman Posted September 19, 2006 Share Posted September 19, 2006 Let us just say I want to use the script on the untitled.bmp from the first post. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 19, 2006 Moderators Share Posted September 19, 2006 Let us just say I want to use the script on the untitled.bmp from the first post.You'll find that if there is an example pic, there is an example script to use with that pic, examine that, because you're answers have already been answered. If there's something you don't understand post your question in the support forum. 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 More sharing options...
pingpong24 Posted October 8, 2006 Author Share Posted October 8, 2006 Oky now you can create a difination very easily!! most of the professonal will look and laugh at the coding but i coded as one off, so i used any random verable name, as i dont plan on EVER going back and updating this piece of code.Java version of this OCR is coming out shortly, here is a un-debuged semi-working version, all it needs is the serialise array part fixing.scroll down for images of the difinition maker.Enjoy. expandcollapse popup/** * This is a number ocr program that can be used to * take data from the window and put into machine readable writing format. * All cridits goes to Royal Miah, for making this wonderful piece of code * * @author Royal Miah * @version v1.0 OCT 2006 */ import java.awt.Color; import java.awt.*; public class OCR { // constructor private Robot robot; public int p = 0; public String RESULT_OF_OCR; public OCR() { try { robot = new Robot(); } catch (AWTException e) { } } public String convertColorToHexString(java.awt.Color c) { String str = Integer.toHexString( c.getRGB() & 0xFFFFFF ); return ("000000".substring( str.length() ) + str.toUpperCase() ); } public String xyscan(int y, int x) { Color c = robot.getPixelColor(x,y); String xy = convertColorToHexString(c); return xy; } //ocr method, here the use declars the top left X and Y // and the bottom right X and Y public String OCR(int ax, int ay, int dx, int dy) { int width = dx - ax; // works out how much the width is from top to bottom int length = dy - ay; // works out the length of the scan from lef tto right String[][] Character = new String[width][length]; int[] Diff = new int[width]; for (int xwidth = 0; xwidth < width -1; xwidth++) { for (int xlength =0; xlength < length -1; xlength++) { Character[xwidth][xlength] = xyscan(ax, ay); // ENTIRE AREA HAS BEEN SCANNED AND PUT INTO AN ARRAY if (Character[xwidth][xlength] == "000000") //serialising array { if (p==1) { p++; } int div = xwidth; int ps = xwidth - div; Diff[ps] = Diff[ps]+1; } } ay++; } ax = ay +1; ay = ay - length; // END of formal OCR code reminder is diffination // insert difination here for (int xwidth = 0; xwidth < width -1; xwidth++) { if ( Diff[xwidth+0] == 1 && Diff[xwidth+1] == 1 && Diff[xwidth+2] == 7) { RESULT_OF_OCR = "1"; } } return RESULT_OF_OCR; } }expandcollapse popup#cs // This difinition creator was created by ROYAL MIAH, all rights reserved OCT 2006 // If you wish to make any modification please do so, just keep my name // All cridits got to Royal Miah // Ntl_cable_guy (@T) hotmail.com #ce #include <GUIConstants.au3> $Form1 = GUICreate("NumCR Definition Creator by Royal Miah (c) 2006 v1.0", 757, 525, 269, 178) $CharName = GUICtrlCreateInput("", 560, 59, 161, 21) GUICtrlCreateLabel("Name of the character i.e. number", 559, 35, 165, 17) $DifRow = GUICtrlCreateCombo("1", 560, 106, 121, 21) GUICtrlSetData(-1,"2|3|4|5|6|7|8|9|10","11"); GUICtrlCreateLabel("What is the width of the character", 560, 86, 164, 17) $Define = GUICtrlCreateButton("Define", 560, 136, 81, 25, 0) $ASource = GUICtrlCreateEdit("", 48, 184, 665, 145) GUICtrlSetData($ASource, "") GUICtrlCreateLabel("Autoit Source", 48, 160, 68, 17) $Edit1 = GUICtrlCreateEdit("", 48, 360, 665, 129) GUICtrlCreateLabel("Java Source", 48, 336, 64, 17) $Edit2 = GUICtrlCreateEdit("", 32, 16, 481, 129, 0, 0) GUICtrlSetData($Edit2, "Instruction on how to use this program"&@CRLF&""&@CRLF&"Select the number of width of the character you want to create a difinition for"&@CRLF&"then type the name of the character i.e. "&Chr(34)&"1"&Chr(34)&" without "&Chr(34)&""&Chr(34)&" once you have done"&@CRLF&"that all you have to do next is enter the values of each black pixels of your"&@CRLF&"character manually, where it says #."&@CRLF&""&@CRLF&"Each black pixel per row.") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Define $som = GUICtrlRead($DifRow) $somels = GUICtrlRead($CharName) $rox = _CreateDiffAu($som,$somels) $pox = _CreateDiffJava($som, $somels) GUICtrlSetData($ASource,$rox) GUICtrlSetData($Edit1,$pox) Case Else ;;;;;;; EndSelect WEnd Func _CreateDiffAu($rows, $charaname) $STRINGVERIABLE = "" For $xwidth = 0 To $rows -1 $STRINGVERIABLE &= " $row[$xwidth+"&$xwidth&"] = # And" Next $presult = "If "&StringTrimRight($STRINGVERIABLE, 4) $presult &= " Then $result &= """&$somels&""" EndIf" $result = $presult Return $result EndFunc Func _CreateDiffJava($rows, $charaname) $STRINGVERIABLE = "" For $xwidth = 0 To $rows -1 $STRINGVERIABLE &= " row[xwidth+"&$xwidth&"] == # &&" Next $presult = "If ("&StringTrimRight($STRINGVERIABLE, 2) $presult &= ") { result &= """&$somels&""" }" $result = $presult Return $result EndFunc ExitOCRdif.au3 NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
sonicxtacy02 Posted October 31, 2006 Share Posted October 31, 2006 (edited) call me crazy but the above picture that gives the width for E does not make sense to me. I'm having a hard time creating a definition for my file and the examples arent clicking. Maybe someone will help shed some light. In the previous post it says there are 2 on row 1 for that E. I count 6 dots which make up the top of the E. Now... there are two dots that make the first column in the E but thats not what the definition creator is requesting. Can anyone help me to understand the above example. Eventually i want to be able to read the numbers in the white box where it says "1.0 mi"also the definition creator is limited to 10 pixels for width... any way to increase this? As you can see in my image there are more than 10 pixels of width for those characters.bdit.bmp Edited October 31, 2006 by sonicxtacy02 Link to comment Share on other sites More sharing options...
Fossil Rock Posted November 1, 2006 Share Posted November 1, 2006 Take a look at this..... Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
Lytus Posted November 3, 2006 Share Posted November 3, 2006 call me crazy but the above picture that gives the width for E does not make sense to me. I'm having a hard time creating a definition for my file and the examples arent clicking. Maybe someone will help shed some light. In the previous post it says there are 2 on row 1 for that E. I count 6 dots which make up the top of the E. Now... there are two dots that make the first column in the E but thats not what the definition creator is requesting. Can anyone help me to understand the above example. Eventually i want to be able to read the numbers in the white box where it says "1.0 mi"also the definition creator is limited to 10 pixels for width... any way to increase this? As you can see in my image there are more than 10 pixels of width for those characters.Yea, he has row and column backwards.I have a suggestion on augmenting this code to allow for more accurate character identification:1) Expand the function to _OCR($Ax, $Ay, $Dx, $Dy, $CharColor), where $CharColor is the hex value of the color, and replace the "000000" with $CharColor (could make it optional, too, and have it default to black)2) You know the width of the characters that are giving you trouble are the same, so just use that width and count pixel colors by row instead of column. Hence, "b" and "p" will look the same by column but not by row. Keep in mind this still won't work with some cases, such as / v. \, but I'm sure there's a way to do some more CPU intensive algorithms to tell these 2 apart.It's just an idea right now cuz it's late for me. Hopefully I'll have some code samples up in a few days. Link to comment Share on other sites More sharing options...
Lytus Posted November 3, 2006 Share Posted November 3, 2006 (edited) I've adjusted things to decrease processing time and increase functionality. Here's a sampling: expandcollapse popupDim $result While $xwidth <= $width - 1 Select Case $column[$xwidth] = 3 AND $column[$xwidth+1] = 3 AND $column[$xwidth+2] = 9 AND $column[$xwidth+3] = 3 AND $column[$xwidth+4] = 4 $result &= "$" $xwidth += 4 . . . Case Else $xwidth += 1 WEnd ;_OCRrow: Handles collisions in the column pixel counting function by evaluating the rectangle that contains the letter by row ; rather than column, increasing detection. To use, just call this function in the above case statements where there are two ; different letters with the same column pixel count. ;Parameters: The width of the CURRENT letter (not the width of the entire segment), the height of the segment, the char array ; that contains the bitmap in hex format, the current color of the numbers/letters you're looking for in hex, and ; the particular case you're dealing with (p v. b; q v. d; etc.) Func _OCRrow($width, $height, $char, $charColor, $case) $p = 1 Dim $row[$width] For $xheight = 0 To $height - 1 For $xwidth = 0 To $width - 1 If $char[$xwidth][$xheight] = $charColor Then If $p = 1 Then $div = $xwidth $p += 2 EndIf $x = $xwidth - $div $row[$x] +=1 EndIf Next Next Select Case $case = 1 ;etc. Case $case = 2 ;. Case $case = 3 EndFunc Keep in mind that I just wrote this quickly and haven't tested it, but I hope folks get the idea. The Case block will keep the CPU from checking every single If statement, and I also made it skip over areas once it's determined that the space is occupied by a character. The old version would start looking for a new character in the middle of an old character, and it's safe to assume that characters do not start in the middle of other characters. Thanks a ton for the original code. I hope this helps. Edited November 7, 2006 by Lytus Link to comment Share on other sites More sharing options...
pippi Posted November 5, 2006 Share Posted November 5, 2006 Lytus: Can you give a comprehensive example on how to use your optimized OCR function? I am not much of a programmer, but i manage to get the OCR from the threadstarter to work. Link to comment Share on other sites More sharing options...
sonicxtacy02 Posted December 5, 2006 Share Posted December 5, 2006 pingpong i have your ocr reader working great. I appreciate all your effort. I have a question though. The function seems to work great with numbers but when i define capital letters it can hardly read any of them. Why is this? Is there something in the function that limits its effectiveness with letters? Link to comment Share on other sites More sharing options...
pingpong24 Posted February 9, 2007 Author Share Posted February 9, 2007 feels so good that someone used my OCR, program and actually mange to get it to work. next version will have recursion so it should be much faster. NumCR Super Fast EASY NUMBER OCR, easiest and the fastest AUTOIT OCR released on this forum Link to comment Share on other sites More sharing options...
myspacee Posted April 25, 2008 Share Posted April 25, 2008 try this, and find very interesting...Is possible to read digital clock number in your opinion ?With webcam script is easy to have only number on screen,so if is possible to create definition, things not to be too hard...some question :- i don't understand if this OCR identify an area or a point (x,y) ? - is possible to drawn a square around monitored area ?Sorry for bad english but can be an idea to utilize this nice job.Thank you for your timem. Link to comment Share on other sites More sharing options...
victor Posted May 5, 2008 Share Posted May 5, 2008 need help , when I run the script with the example bmp it only return " . " or " .. " instead of numbers. ------------------------------------------ #include "NumCR.au3" $test = _OCR(0, 0, 300, 300) MsgBox(0, "Example", $test) ------------------------------------------ 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