eskermeko Posted April 10, 2007 Share Posted April 10, 2007 (edited) Hi This is my first post here and I would just like to write how wonderful this software is. Its helped me alot. I have been writing my first OCR. But I am using PixelChecksum and with a gradient background on the pictures I am finding it very hard. Was wondering can I count the pixels of a certain colour in a specified block of a picture. I would like to count the white pixels. Any help welcome. Edited April 10, 2007 by eskermeko Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 11, 2007 Share Posted April 11, 2007 (edited) Since you didn't get any inteligent answers, I'll give you one of mine instead... OCR is hard, very hard. Differences in fonts, font size, bold, italics, underlining, color, superscript, subscript, etc., etc. make it an extremely hard thing to code. If you use the Search on this forum for OCR, you'll get a lot of discussion about the dificulties. You could, just, create OCR functions in AutoIT. But they will be very limited, to a particular font and size for example, and likely very slow. Search will find you some examples, but I think you will find they were coded for very limited special circumstances.For some idea of the level of effort that goes into and OCR project, take a look at Tesseract or the more recent OCRopus projects.As for your actual AutoIT question, you can walk through a graphic space on the screen with For/Next loops doing PixelGetColor() and count pixels with a given color. You can even do it inside a BMP file of an image fairly straight forwardly. But interpreting what you get will become horribly complicated realy quickly, so think about other ways to get whatever it is done, too. Edited April 11, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 (edited) Since you didn't get any inteligent answers, I'll give you one of mine instead... OCR is hard, very hard. Differences in fonts, font size, bold, italics, underlining, color, superscript, subscript, etc., etc. make it an extremely hard thing to code. If you use the Search on this forum for OCR, you'll get a lot of discussion about the dificulties. You could, just, create OCR functions in AutoIT. But they will be very limited, to a particular font and size for example, and likely very slow. Search will find you some examples, but I think you will find they were coded for very limited special circumstances. For some idea of the level of effort that goes into and OCR project, take a look at Tesseract or the more recent OCRopus projects. As for your actual AutoIT question, you can walk through a graphic space on the screen with For/Next loops doing PixelGetColor() and count pixels with a given color. You can even do it inside a BMP file of an image fairly straight forwardly. But interpreting what you get will become horribly complicated realy quickly, so think about other ways to get whatever it is done, too. Thanks I quickly put this together $xstart = 253 $ystart = 64 $xend = 262 $yend = 74 $x = $xstart $y = $ystart $count = 0 while $xend > $x if PixelSearch( $x, $y, $y+1, $y+1, 0xFF0000 ) Then $count = $count + 1 EndIf $x = $x + 1 $y = $y +1 Wend MsgBox(0,"Count=", $count) Im new at this. Somethings wrong, dunno what. I keep on getting same number(9) when I count. Edited April 11, 2007 by eskermeko Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 (edited) Oops no wait thats totally wrong ,Think PixelgetColour right. I realized the Pixelsearchcolor should be: $pixel = PixelSearch( $x, $y, $y+1, $y+1, 0xFFCC00 ) If Not @error Then $count = $count + 1 EndIf And Im doing the x y wrong also Edited April 11, 2007 by eskermeko Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 Well I had to do this: while $yend > $y $z = $y + 1 while $xend > $x $var = PixelGetColor( $x , $z ) If $var = "16763904" then $count = $count + 1 EndIf $x = $x + 1 Wend $x = $xstart $y = $y + 1 Wend Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 11, 2007 Share Posted April 11, 2007 (edited) If you will look for the pixels more than once, you want it in a function you call over and over again. Here is an example of search a rectangular area for three different colors:; Count pixels of a certain color in a 100x40 box starting at 200,300 Dim $xstart = 200, $width = 100 Dim $ystart = 3000, $height = 40 $SearchColor = 0 $Result = _PixelGetColorCount($xstart, $ystart, $width, $height, $SearchColor) MsgBox(64, "Results", "Black pixels found: " & $Result) $SearchColor = 0xFFFFFF $Result = _PixelGetColorCount($xstart, $ystart, $width, $height, $SearchColor) MsgBox(64, "Results", "White pixels found: " & $Result) $SearchColor = 16763904 $Result = _PixelGetColorCount($xstart, $ystart, $width, $height, $SearchColor) MsgBox(64, "Results", "Pixels found of color '16763904': " & $Result) ;----------------------------- ; Function _PixelGetColorCount() ; Returns the number of pixel of a certain color ; Call with: _PixelGetColorCount($x, $y, $w, $h, $color) ; Returns count of matching pixels on success ;----------------------------- Func _PixelGetColorCount($x, $y, $w, $h, $color) Local $count = 0, $IntX, $IntY For $IntX = $x To $x + $w For $IntY = $y To $y + $h If PixelGetColor($IntX, $IntY) = $color Then $count += 1 Next Next Return $count EndFunc ;==>_PixelGetColorCount Edit: From another post, there is a reference to the MODI OCR, which is the Microsoft Office Document Imaging interface. Gives you some more options if you have MS Office 2003 or later installed, but would require learning to use the COM object capabilities of AutoIT to take advantage of. Edited April 11, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 THanks I was working on this today What a mission. But all for nothing cause some of the letters has the same amount of pixels. Maybe I can search by shade of colours With the code I scanned every vertical line and when I found a blank vertical I would reset the counters for a new Letter. So it doesn't just read one letter. expandcollapse popup$xstart = 161 $ystart = 21 $yend = 31 $count = 0 $height = $yend - $ystart $width = 24 $colour = "16763904" $x = $xstart $y = $ystart $count2 = 0 $crashProtect = 0 FOR $a = $width to 1 Step -1 ;Init count $count = 0 ;count Vertical Lines $count = CountVertical($x,$y,$height,$colour) ;Move on xaxis $x = $x + 1 ;Add Vertical lines together $count2 = $count2 + $count ;Print & reset counters on new line IF $count = 0 THEN IF $count2 > 1 THEN ControlSend("Untitled - Notepad", "", "Edit1", " . ") ControlSend("Untitled - Notepad", "", "Edit1", $count2) ControlSend("Untitled - Notepad", "", "Edit1", " . ") ENDIF $a = $width $crashProtect = $crashProtect + 1 $count2 = 0 Else $crashProtect = 0 ENDIF ;Protect against infinite loop IF $crashProtect > 25 Then ExitLoop EndIf Next ;Functions Func CountVertical($x,$y,$height,$colour) FOR $i = $height to 1 Step -1 $var = PixelGetColor( $x , $y ) If PixelGetColor($x, $y) = $colour Then $count += 1 $y = $y + 1 Next return $count EndFunc Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 I changed the function to see if I can get shades But this does not seem to work ;Functions Func CountVertical($x,$y,$height,$colour) $z = $y FOR $i = $height to 1 Step -1 $z = $z + 1 $var = PixelSearch($x, $y,$x,$z,$colour, 10) If Not @error Then $count += 1 EndIf Next return $count EndFunc Am I doin it right? Any help appreciated Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 I changed the function to see if I can get shades But this does not seem to work ;Functions Func CountVertical($x,$y,$height,$colour) $z = $y FOR $i = $height to 1 Step -1 $z = $z + 1 $var = PixelSearch($x, $y,$x,$z,$colour, 10) If Not @error Then $count += 1 EndIf Next return $count EndFunc Am I doin it right? Any help appreciated Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 I changed the function to see if I can get shades But this does not seem to work ;Functions Func CountVertical($x,$y,$height,$colour) $z = $y FOR $i = $height to 1 Step -1 $z = $z + 1 $var = PixelSearch($x, $y,$x,$z,$colour, 10) If Not @error Then $count += 1 EndIf Next return $count EndFunc Am I doin it right? Any help appreciated Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 Something went wrong with browser and that s why it printed three posts Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 11, 2007 Share Posted April 11, 2007 I changed the function to see if I can get shades But this does not seem to work Am I doin it right? Any help appreciated This works to count one vertical stripe of pixels: ;Functions Func CountVertical($x, $y, $height, $colour) Local $PixY, $count = 0 For $PixY = $y To $y + $height PixelSearch($x, $PixY, $x, $PixY, $colour, 10) If Not @error Then $count += 1 Next Return $count EndFunc ;==>CountVertical Something went wrong with browser and that s why it printed three posts You realize writing your own web browser might be easier than your own OCR? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
eskermeko Posted April 11, 2007 Author Share Posted April 11, 2007 (edited) Thanks very much LOL! I have written a simple web browser with C# but this is insane man Edited April 11, 2007 by eskermeko Link to comment Share on other sites More sharing options...
eskermeko Posted April 12, 2007 Author Share Posted April 12, 2007 Thanks for the help, I finally got it working. I was adding the vertical lines all this time instead of just putting them next to each other. That fixed the whole thing. It was pretty frustrating and hard to do but in the end worth it. Link to comment Share on other sites More sharing options...
seangriffin Posted February 16, 2009 Share Posted February 16, 2009 (edited) You could check out my Tesseract OCR UDF if you are after a free OCR solution: Tesseract UDF Cheers, Sean. Edited February 16, 2009 by seangriffin Cheers, Sean. See my other UDFs: Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax See my other Tools: Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia Link to comment Share on other sites More sharing options...
Marlo Posted February 16, 2009 Share Posted February 16, 2009 2 year bump? nice o_0 Click here for the best AutoIt help possible.Currently Working on: Autoit RAT Link to comment Share on other sites More sharing options...
dgm5555 Posted November 1, 2012 Share Posted November 1, 2012 I've just uploaed this native autoit screen OCR (working reasonably well, but still not totally bug-free):-Also this can search for a pixel pattern (eg a word), but doesn't return the actual text: May be useful.David Link to comment Share on other sites More sharing options...
BrewManNH Posted November 1, 2012 Share Posted November 1, 2012 @dgm5555 Why did you post this here? This thread is 5 years dead, with a 3 year old necroing attempt on it already. Please don't do that again. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 1, 2012 Moderators Share Posted November 1, 2012 dgm5555, You have necro-posted twice today - and both times hijacked the threads to publicize your own. Please do not do it a third time. 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