Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Capture Screen Text using OCR

Here’s a way to get Screen text from any application – even from an image – using OCR and a free open source tool called Tesseract.

First, you need to download and install Tesseract. You can get it here.

Tesseract is a command line utility. The most basic syntax is:

tesseract.exe input_image_file output_text_file

So you could call it from a Macro Scheduler script something like this:

//Capture screen to bmp file - you could instead capture only a window or use FindObject to get coordinates of a specific object

//run tesseract on the screen grab and output to temporary file
Run>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" "%SCRIPT_DIR%\screen.bmp" "%SCRIPT_DIR%\tmp"

//read temporary file into memory and delete it

//Display the text in a message box

This example simply captures the entire screen. You probably wouldn’t normally want to do this. Instead you could Capture a specific window:

//Capture just the Notepad Window
SetFocus>Untitled - Notepad
GetWindowPos>Untitled - Notepad,X1,Y1
GetWindowSize>Untitled - Notepad,w,h

Or even a specific object:

//capture just the editor portion of notepad ...
SetFocus>Untitled - Notepad
GetWindowHandle>Untitled - Notepad,hWndParent

Either way you then have a screen bitmap you can pass into Tesseract.

Once you’ve retrieved the text you would probably want to parse it, using e.g. RegEx. Here’s an article on a RegEx expression useful for parsing out data.

No related posts.

This post first appeared on Marcus' Macro Blog - Windows Macro And Windows Au, please read the originial post: here

Share the post

Capture Screen Text using OCR


Subscribe to Marcus' Macro Blog - Windows Macro And Windows Au

Get updates delivered right to your inbox!

Thank you for your subscription