As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Amin.
What it Does
This C# application uses OCR on screen capture image snips using LEADTOOLS Version 19.
Development Progress Journal
Hello, my name is Amin and I’ll be creating a program captures an image from the computer’s screen using a user-selected rectangle, then extracts text from the captured image using LEAD’s Optical Character Recognition (OCR) technology.
I will be coding with C# using VS 2010 since its projects can be easily upgraded to later versions of Visual Studio.
First, I’ll start by creating a form that has the
Leadtools.Controls.ImageViewercontrol to display the captured image and a text box for the recognition result.
To perform screen capturing, I will use the LEADTOOLS
I have added a button to initiate capturing and an event handler to receive the capture image. The entire code needed to do the user-selection screen capturing, or snipping, is about a dozen lines long and took less than an hour to finish. Attempting a similar feat without LEADTOOLS would take most programmers days, or even weeks, if we consider the smooth and flawless mouse-controlled user-interface.
Next, I’ll add code to perform OCR. A good starting point is to download one of the "Minimum OCR demos" on our support forums:
Using code from that page, I was able to implement OCR within one hour as well. Using the image returned from screen capturing with the OCR engine was very simple and straightforward, since the various LEADTOOLS modules are designed to work together seamlessly.
Since most screens have a default resolution of 96 dots per inch, my code changes the image resolution to 150 DPI before using it with OCR. The reason is that OCR takes into consideration the image’s DPI when attempting to recognize the shapes of the characters, and a value of 150 is more suitable for OCR than 96.
Finally, I added a couple of bells and whistles to enable copying either the image or the recognition result text to the Windows clipboard, then spent some time testing, commenting and refining the code.
All in all, the whole thing took less than 6 hours to make.
Please note that LEADTOOLS 19 ships with an OCR and Screen Capture demo that has more advanced features. The demo is installed with the toolkit in these folders:
Download the Project
The source code for this sample project can be downloaded from here. To run the project, extract it to the C:\LEADTOOLS 19\Examples\DotNet\CS directory.