UWP OCR SDK

UWP OCR SDK

Platform : Windows 10

 Add OCR , business card reading technology to your UWP applications quickly and easily. Support Arabic, English, German, East Asian languages and more.

 

Popular Solution Go   Back

C# - OCR using UWP (Windows 10)

Step 1: To install the UWP OCR SDK, begin by launching the setup file (http://www.viscomsoft.com/demo/uwp-ocr-sdk-setup.exe). Select the desired installation folder for the UWP OCR SDK and continue with the installation on your development computer.

Step 2: Launch Visual Studio 2015 or above version of Visual Studio. Select Visual C#, Select Windows - Universal - Blank App.





Step 3: In the Solution Explorer, right-click References, and then click Add Reference.

Step 4: Select Browse tab,  Navigate to the extracted  UWP OCR SDK for REDIST folder, open it, select x64 or x86 or ARM folder, depend on your project target platform and then selected ViscomsoftOCR.winmd , click OK button.

Step 5: Now you will see the ViscomsoftOCR added to References. 


Step 6:Create tessdata folder. 


Step 7. Add the language data files to tessdata folder. In trial version of UWP OCR SDK installer, you can found the language data files in C:\Program Files(x86)\Viscomsoft UWP OCR SDK\Examples\C#2015\OCR\App1\tessdata folder,  it include English, German, French, Italian, Dutch, Portuguese, Spanish language data files.

You may include all language data files to tessdata folder or just include your support language. For example, If you do not need support Spanish language,  you may delete spa.cube.bigrams, spa.cube.fold, spa.cube.lm, spa.cube.nn, spa.cube.params,spa.cube.size, spa.cube.word-freq, spa.traineddata files in tessdata folder.
 
 Finally, If you need additional OCR language (e.g. Arabic, Chinese, Japanese, Hebrew), you may download from
http://www.viscomsoft.com/UWP/uwp-ocr-langpack.zip ,  unzip and copy the language data files to tessdata folder.
 
 Selected the language data files, right click the mouse , select Properties.  Change Build Action to Content.

Step 8. Open MainPage.xaml, In the XAML editor, add the code for appbar and add image control and scrollviewer control for display the image.

 
 

Step 9. Open MainPage.xaml.cs, add the using statement
 
 
using ViscomsoftOCR;
 
using Windows.Storage.Pickers;
 
using Windows.Storage;
 
using Windows.UI.Xaml.Media.Imaging;
 
using Windows.Storage.Streams;
 
using Windows.UI.Popups;

Step 10. In MainPage.xaml.cs, declare _imageFile object.
  private StorageFile _imageFile;

Step 11. In MainPage.xaml.cs , add the code to open picker , let the user select the image file for OCR.
private async void uiOpen_Click(object sender, RoutedEventArgs e)
 {
 FileOpenPicker openPicker = new FileOpenPicker();
 openPicker.ViewMode = PickerViewMode.Thumbnail;
 openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
 openPicker.FileTypeFilter.Add(".jpg");
 openPicker.FileTypeFilter.Add(".jpeg");
 openPicker.FileTypeFilter.Add(".png");
 openPicker.FileTypeFilter.Add(".gif");
 openPicker.FileTypeFilter.Add(".tif");
 
 _imageFile = await openPicker.PickSingleFileAsync();
 
 if (_imageFile == null)
 return;
 
 BitmapImage bitmapImage = new BitmapImage();
 IRandomAccessStream stream = await _imageFile.OpenReadAsync();
 await bitmapImage.SetSourceAsync(stream);
 
 uiInputImage.Source = bitmapImage;
 }

Step 12. In MainPage.xaml.cs , add the code to start the OCR processing.

private async void uiStart_Click(object sender, RoutedEventArgs e)
 {
   if (_imageFile == null)
   return;
 
 try
 {
   IRandomAccessStream stream = await _imageFile.OpenReadAsync();
 
   ViscomsoftOcr ocr = new ViscomsoftOcr();
 
   StorageFolder tessdataFolderobj = await    Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("tessdata");
 
   Language lang = ViscomsoftOCR.Language.English;
   bool result;
 
   result = await ocr.initAsync(lang, tessdataFolderobj.Path);
 
   MessageDialog dlgError =null;
   if (!result)
   {
    dlgError = new MessageDialog("ERROR!!! - Language data not found");
    dlgError.ShowAsync();
    return;
   }
 
   ocr.setImage(stream);
 
   result = await ocr.recognizeAsync();
 
   if (!result)
   {
   dlgError = new MessageDialog("ERROR!!! - recognize error");
   dlgError.ShowAsync();
   return; 
   }
 
   MessageDialog dlg = new MessageDialog(await ocr.getUTF8TextAsync());
   dlg.ShowAsync();
  
 }
 catch (Exception ex)
 {
   MessageDialog dlg = new MessageDialog("ERROR!!! - " ex.Message);
   dlg.ShowAsync();
 }
 
 }
 
 }

Step 12.  Select Build - Rebuild Solution.
 
 You may download the project source code from http://www.viscomsoft.com/UWP/ocr-sdk-csharp-tutorial.zip