This sample demonstrates how to use the Microsoft OCR Library for Windows Runtime to extract text in the specified language from an image.
This sample requires you to download and install the OCR Library into the sample project. The OCR Library is a NuGet package. For more info, see the instructions on this page.
This sample demonstrates following features:
- Extract text in the specified language from an image.
- Overlay extracted text over the image.
The OCR Library reads text from images and returns the text and layout information. All of this happens locally on the user's device. When you add the OCR Library to an application, you control how your application interprets the returned text. When the OCR Library recognizes patterns, such as email addresses, phone numbers, and URIs, your app can launch common actions such as sending an email, making a phone call, or visiting a web site.
To use the OCR Library in your app, call the RecognizeAsync method of the OcrEngine class. This method returns an OcrResult object, which contains the recognized text and its size and position. The result is split into lines, and the lines are split into words.
- The OcrResult contains a collection of OcrLine objects, which you access through the Lines property of the OcrResult.
- Each OcrLine object contains a collection of OcrWord objects, which you access through the Words property of each OcrLine.
- Each OcrWord object specifies the text, size, and position information of the word in the image.
For more info about the OCR Library, see WindowsPreview.Media.Ocr.
To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.
To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.
Downloading and installing the OCR Library
See the NuGet documentation for all the ways you can download and install the NuGet package in your project. To install the package from within Microsoft Visual Studio, do the following:
- In Visual Studio, select PROJECT | Manage NuGet Packages.
- In the Online section, select nuget.org. Search for Microsoft.Windows.Ocr.
- Click Install.
- Select BUILD | Configuration Manager to change the build configuration of your project from AnyCPU to x86, x64, or ARM.
- If Intellisense does not work after you have installed the NuGet package, unload and reload the Visual Studio project. In Solution Explorer, right-click the project and select Unload Project. Then right-click the project again and select Reload Project.
Operating system requirements
Build the sample
- Start Visual Studio Express 2013 for Windows --> and select File > Open > Project/Solution.
- Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Visual Studio Express 2013 for Windows Solution (.sln) file.
- Press F7 or use Build > Build Solution to build the sample.
Run the sample
To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.