sharpnova Posted November 17, 2011 Report Share Posted November 17, 2011 I run an application that displays a number in the upper right of the screen. The number is always in the same place, but it is displayed as an image. I need to receive an alert when that number passes a certain value. Is there a simple OCR solution for this task? Maybe some program that can do OCR processing on a specific region of the screen. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Cory Posted November 17, 2011 Report Share Posted November 17, 2011 Awhile back I posted some messages regarding this and suggested some command-line solutions. Try searching there first. There are some other automation bits of software that can watch an area of the screen for certain matches but I don't think it does OCR. But I imagine you could use simple graphics apps like Irfanview and some simple OCR software to do this all in the background. The other possibility is to use pixel pattern matching. MEP can get the color of a pixel. Many here, including me, have written very complex routines that scan lines of pixels for patterns and such but if what you are looking for is uniform and predictable there might be a simple approach. If there is one number pattern you are looking for you could compare it to any other possible pattern and look for a unique pattern. IE there may be a pixel (or a few) that is only black when this certain number is displayed. EG is I was looking for 25 in a counter. I would look at a pixel at the extreme top left of the 2 that is normally white when a 1 is displayed. Then once that's black look for pixels that are uniquely black only for the number 5. Should work pretty quick. Quote Link to comment Share on other sites More sharing options...
sharpnova Posted November 17, 2011 Author Report Share Posted November 17, 2011 Scanning specific pixels (and the hassle associated with it) was why I was hoping there was an OCR solution. I can try doing it this way but unfortunately, though the text to be scanned is always in the same place, the background behind it (this is a game) changes quite a bit. Might even match the color of the number image occasionally. I read another post of yours regarding OCR but I didn't see any mention of a utility that could scan an arbitrary region. Quote Link to comment Share on other sites More sharing options...
acantor Posted November 18, 2011 Report Share Posted November 18, 2011 An OCR scan, if it exists, would be ideal. But there may be other ways to detect the numbers. What is it exactly that contains the image of the number? Is it a control in a Windows application? Is it an image on a Web page? If the former, MEP may be able to gather information about the control. If the latter, MEP may be able to suss out its properties, which might include clues about, or reveal the content: <img src="../images/3.jpg" alt="Glowing Numeral 3" /> To expand on Corey's explanation: Pixel sniffing routines (to detect patterns of colours) can be made to work reliably. But these projects are not for the faint of heart. The projects can eat a lot of time to figure out appropriate scripting approaches. One of my MEP scripts performs over 1000 steps each time it runs to find colours and keep track of the patterns. The macro executes almost instantaneously, as it uses variables to track position rather than mouse cursor movements. Rather than this: Get Pixel Color from Beneath the Mouse into %PixelColour% It uses this: Get Pixel Color at (%x%, %y%) Relative to Current Window into %PixelColour% For complex pixel sniffing problems, I find the second approach runs significantly faster than the first. Quote Link to comment Share on other sites More sharing options...
lemming Posted November 29, 2011 Report Share Posted November 29, 2011 Like Cory says, if your text appears in exactly the same spot every time, then you may not even need OCR. Anyway, you could use MEP's windows resizing and repositioning commands to ensure this. Does the text also appear in the exact font and color each time? You can think of the search area as a square grid, and each number has a unique layout on the grid. For example, the number 42 has a different layout when compared to 76. So all you need to do is compare pixels at a dozen (or so) precise coordinates, and you'd have a crude form of OCR. MEP should be fast enough to do this every second, or every 1/2 second. Finding out the precise pixel coordinates can be tricky. You will probably need to use Window's built-in screen magnifier (It's just called "Magnifier" in Win 7; I forgot what it's called in earlier versions) and also AutoIt3 Window Spy, a utility which will report the exact coordinates of your mouse cursor. AutoIt3 Window Spy is installed as a part of AutoHotkey_L (http://l.autohotkey.net/). Quote Link to comment Share on other sites More sharing options...
Cory Posted November 30, 2011 Report Share Posted November 30, 2011 When I was hunting around on this I couldn't find one either. My plan was then to use two programs. One was Tesseract, a free command line OCR application. I had experimented with it on another project but it was not accurate enough but for a clean bit of screen text I think it would do the trick. The other part of the solution was to use a screen capture program like Snagit or Irfanview. I found an alternative solution on the project so I didn't go down that road. Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 30, 2011 Report Share Posted November 30, 2011 a utility which will report the exact coordinates of your mouse cursor. How does this differ from the Macro Express Mouse Locator? To launch, click Tools, Launch Mouse Locator. Quote Link to comment Share on other sites More sharing options...
lemming Posted December 2, 2011 Report Share Posted December 2, 2011 Just remembered that I came up with an “image capture and compare” solution last year for MEP. This can serve as an OCR replacement, and might suit your purpose if the screen info doesn't change rapidly: http://pgmacros.invisionzone.com/index.php?showtopic=4531 My script uses external programs though (IrfanView and md5.exe), and it is not very fast and needs to save to disk. You might be able to speed things up with a RAM drive. Quote Link to comment Share on other sites More sharing options...
terrypin Posted December 2, 2011 Report Share Posted December 2, 2011 I'd use Snagit. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
lemming Posted December 2, 2011 Report Share Posted December 2, 2011 I'd use Snagit. -- Terry, East Grinstead, UK Snagit works great, but it is not freeware. It cost about $50. Quote Link to comment Share on other sites More sharing options...
terrypin Posted December 2, 2011 Report Share Posted December 2, 2011 Snagit works great, but it is not freeware. It cost about $50. True, but Sharpnova didn't say it had to be free! Good value IMO, couldn't manage without it. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.