Jump to content
Macro Express Forums

OCR solution to read an image-based number in the corner of the screen


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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/).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...