Introduction
Windows 8 is finally here, and LEADTOOLS is ready to help
you hit the ground running with its new WinRT
SDK. The Windows Store is ripe with opportunities to create a multitude of
imaging apps and LEADTOOLS has it all: support for 150+ formats, PDF and PDF/A,
touch screen enabled viewer controls, OCR, Barcode, DICOM, PACS, annotations,
image processing and more. Any Windows Store application can easily be created
with the help of LEAD Technologies’ advanced and award-winning Document and
Medical imaging SDKs.
One such opportunity is with Optical Character Recognition.
The state of the art LEADTOOLS
OCR SDK provides native WinRT libraries that can run on any desktop, tablet
or mobile device. Scan and convert a document to searchable PDF for archival,
or snap a picture of a business card and add it to your contacts. Whatever
your mind can dream up, LEADTOOLS can help you get there.
Key WinRT Features in LEADTOOLS
-
Native WinRT binaries for Win32, x64 and ARM
-
Develop Windows Store applications that target any Windows 8
desktop, tablet or mobile device
-
Image viewer controls designed specifically for WinRT and Windows
Store apps
-
Compatible with Expression Blend
-
Supports both mouse and multi-touch gesture input
-
Built-in interactive modes such as pan, scale, pinch and zoom,
magnifying glass and more
-
Automatically scale images to fit, fit width and stretch to the
control size
-
Load, convert and save more than 150 image formats
-
Advanced bit depth, color space and compression support for
common formats including PDF, PDF/A, JPEG, JPEG 2000, TIFF, JBIG2 and more
-
Comprehensive Annotation and Markup including geometric shapes,
sticky note, redact, highlight and rubber stamp
-
Barcode reading and writing for QR, PDF417, DataMatrix, UPC/EAN
and more
-
Read, write and edit DICOM Data Sets with Window Leveling and
DICOM Annotations
-
Use DICOM Communication to create native WinRT PACS clients
-
Interoperability between the LEADTOOLS
RasterImage
object and WinRT ImageSource
or WritableBitmap
objects
OCR Features for WinRT
-
Fast, accurate and reliable optical character recognition for use
in any application or environment
-
Choose from several built-in and custom dictionaries to improve
OCR results
-
Recognize text from over 30 languages and character sets
including English, Spanish, French, German, Japanese, Chinese, Arabic and more
-
Automatically detect the document's language
-
Full page analysis and Zonal recognition
-
Unique color and bitonal image recognition
-
Automated document image cleanup
-
Output searchable text document formats such as PDF, PDF/A, XPS
and Word, maintaining the original look and feel
The WinRT OCR Code
The following example covers the foundational pillars of any
OCR application: conversion to searchable text formats (e.g. PDF, PDF/A, DOCX,
TXT, etc.), full page text recognition, and zonal (region of interest) text
recognition.
We begin by initializing the LEADTOOLS OCR engine and
preparing a document.
string strEngineDirectory = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, @"OCR");
_ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
_ocrEngine.Startup(null, null, string.Empty, strEngineDirectory);
_ocrDocument = _ocrEngine.DocumentManager.CreateDocument();
The final preparation step is to load an image and add it as
a page to our document. LEADTOOLS is capable of processing an infinite number
of pages, but for this example we will only add a single page.
var picker = new FileOpenPicker();
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.ViewMode = PickerViewMode.List;
foreach (var imageFormat in _imageFormats)
picker.FileTypeFilter.Add(imageFormat.Extension);
var file = await picker.PickSingleFileAsync();
if (file == null)
return;
ILeadStream leadStream = LeadStreamFactory.Create(file);
RasterCodecs codecs = _ocrEngine.RasterCodecsInstance;
RasterImage rasterImage = await codecs.LoadAsync(leadStream, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);
_ocrDocument.Pages.Clear();
_ocrPage = _ocrDocument.Pages.AddPage(rasterImage, null);
OCR to PDF/A
Converting scanned images to searchable text formats such as
PDF, PDF/A, Word, XML and TXT is both easy to implement and extremely
customizable with LEADTOOLS. The Recognize
function
processes the document and stores the recognition data internally as EMF.
_ocrPage.AutoZone(null);
_ocrPage.Recognize(null);
After the recognition is complete, the OCR engine uses the DocumentWriter
class to convert the OCR results to any
format. Each supported format comes with its own set of options that extends
the DocumentOptions
base class. Below we set the
format to PDF/A and then save the document.
ILeadStream leadStream = LeadStreamFactory.Create(file);
PdfDocumentOptions options = _ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
options.DocumentType = PdfDocumentType.PdfA;
_ocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, options);
await _ocrDocument.SaveAsync(leadStream, DocumentFormat.Pdf, null);
OCR to Text
Converting an image to raw text couldn’t be any easier with
the RecognizeText
function which returns the results as
a string object. In our example, we simply set the value of a TextBlock
object to display it to the user.
_ocrPage.AutoZone(null);
TextResults.Text = _ocrPage.RecognizeText(null);
Zonal OCR
Instead of using LEADTOOLS’ AutoZone
function, developers can define the page’s zones in any number of ways
including modifying existing zones, programmatically adding zones for defined
form fields, or allowing the user to manually draw a region of interest which
we will do here.
The LEADTOOLS RasterImageViewer
control supports both mouse and multi-touch gesture input and provides many
useful events and callbacks. The RubberBandCompleted
event is the perfect event to handle this task.
ImageViewerRubberBandInteractiveMode rubberband = new ImageViewerRubberBandInteractiveMode();
rubberband.RubberBandCompleted += delegate(object rubberBandSender, ImageViewerRubberBandEventArgs rubberBandEventArgs)
{
Rect bounds = new Rect(rubberBandEventArgs.Point1, rubberBandEventArgs.Point2);
if (bounds.Width > 1 && bounds.Height > 1)
{
bounds = rasterImageViewer1.ConvertRect(CoordinateType.Control, CoordinateType.Image, bounds);
_ocrPage.Zones.Clear();
OcrZone zone = OcrTypeManager.CreateDefaultOcrZone();
zone.ZoneType = OcrZoneType.Text;
zone.Bounds = LeadRectHelper.Create((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height);
_ocrPage.Zones.Add(zone);
TextResults.Text = _ocrPage.RecognizeText(null);
}
};
rasterImageViewer1.DefaultInteractiveMode = rubberband;
Conclusion
LEADTOOLS provides developers with access to the world’s
best performing and most stable imaging libraries in an easy-to-use, high-level
programming interface enabling rapid development of business-critical
applications.
Its WinRT OCR SDK is only one of the many technologies
LEADTOOLS has to offer. For more information on our other products, be sure to
visit our home
page, download a free fully functioning evaluation SDK, and take advantage
of our free technical support during your evaluation.
Download the Full WinRT Example
You can download a fully functional demo which includes the
features discussed above. To run this example you will need the following:
Support
Need help getting this sample up and going? Contact
our support team for free technical support! For pricing or licensing
questions, you can contact our sales team (sales@leadtools.com)
or call us at 704-332-5532.
For More Information on WinRT Imaging with LEADTOOLS