天天看点

LEADTOOLS WinRT OCR识别代码示例

LEADTOOLS WinRT SDK提供了开发人员创建Windows Store应用程序所需的所有最先进的成像技术,比如触屏查看器,格式,压缩,图像处理,注释和标记,OCR,条形码,PACS等等。借助于LEADTOOLS先进的文档和医疗成像技术,开发人员可以轻松创建Windows Store应用程序。

LEADTOOLS OCR SDK提供了原生WinRT库,可在桌面,平板电脑或移动设备上运行。不管是扫描并将文档转换为可搜索的PDF文档,还是拍摄名片并将其添加到联系人中,LEADTOOLS 都可帮你实现。

LEADTOOLS中的WinRT功能:

  • 适用于32位、64位和ARM的原生WinRT库
  • 开发适用于Windows 8 桌面、平板电脑和移动设备的Windows Store应用程序
  • 专为WinRT和Windows Store应用程序而设计的图像查看器控件
    • 兼容Expression Blend
    • 支持鼠标和多点触摸手势输入
    • 内置互动模式,如平移,缩放,捏和缩放和放大镜
    • 自动缩放图像至适合宽度
  • 加载,转换和保存超过150个图像格式,如PDF, PDF/A, JPEG, JPEG 2000, TIFF和JBIG2等
  • 全面的注释和标记,包括几何形状,便条,编校,亮点和橡皮图章
  • 支持条形码读写,包括:QR码,PDF417,二维码,UPC/EAN等
  • 读写和编辑DICOM数据集
  • 使用DICOM通信创建本地WinRT PACS客户端

LEADTOOLS WinRT 的OCR功能

  • 适用于任何应用程序和环境的快速,准确,可靠的光学字符识别
  • 全页识别和纬向识别
  • 自动检测文档语言
  • 识别语言和字符集超过30种,包括英语,西班牙语,法语,德语,日语,中文,阿拉伯文
  • 独特的彩色和黑白图像识别
  • 自动文档图像清理
  • 输出可搜索的文本文档格式,包含PDF,PDF / A,XPS和Word

WinRT OCR代码

下面的示例展示了OCR应用程序的基本功能:转换成可搜索的文本格式(如PDF,PDF / A,DOCX,TXT等),整页文字识别,纬向文本识别。

首先,我们初始化LEADTOOLS OCR引擎,并准备一份文档:

// Create an instance of the engine
string strEngineDirectory = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, @"OCR");
_ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
_ocrEngine.Startup(null, null, string.Empty, strEngineDirectory);

// Create the OCR document
_ocrDocument = _ocrEngine.DocumentManager.CreateDocument();
           

接下来,加载图像,并把图像添加到文档中。

// Show the file picker
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;

// Create a LEADTOOLS stream from the file
ILeadStream leadStream = LeadStreamFactory.Create(file);

// Get the RasterCodecs object to load the image from the OCR engine
RasterCodecs codecs = _ocrEngine.RasterCodecsInstance;

// Load the image (first page only)
RasterImage rasterImage = await codecs.LoadAsync(leadStream, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

// Add it to the OCR engine
// Check if we have previous pages, remove them
_ocrDocument.Pages.Clear();
_ocrPage = _ocrDocument.Pages.AddPage(rasterImage, null);
           

OCR to PDF/A

将扫描图像转换成可搜索文本(PDF,PDF / A,Word,XML和TXT)非常容易。识别功能处理文档并将识别数据存储为EMF。

// Auto-zone the page
_ocrPage.AutoZone(null);

// Recognize the page
_ocrPage.Recognize(null);
           

识别完成后,OCR引擎利用DocumentWriter类将OCR结果转换为任意格式。

// Create a LEADTOOLS stream from the file
ILeadStream leadStream = LeadStreamFactory.Create(file);

// Set PDF output options, use PDF/A
PdfDocumentOptions options = _ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
options.DocumentType = PdfDocumentType.PdfA;
_ocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, options);

// Save the OCR'd document as searchable PDF
await _ocrDocument.SaveAsync(leadStream, DocumentFormat.Pdf, null);
           
LEADTOOLS WinRT OCR识别代码示例
LEADTOOLS WinRT OCR识别代码示例

OCR to Text

利用RecognizeText功能将图像转换为原始文本也非常的容易。

// Auto-zone the page
_ocrPage.AutoZone(null);

// Recognize the page and get the results as text
TextResults.Text = _ocrPage.RecognizeText(null);
           
LEADTOOLS WinRT OCR识别代码示例
ocr

继续阅读