快速使用Aspose.OCR对图片上的文本进行OCR识别

作者:控件中国网   出处:控件中国网   2015-07-16 09:37:04   阅读:35

开发人员可以利用Aspose.OCR快速准确的对图片上的文本进行识别,该控件提供了 OcrEngine类专门用于OCR的识别,使用起来相当简单,只需对类的Image属性进行赋值即可,默认情况下是识别英语,如果是识别其他语言则需要 LanguageFactory.Load方法加载相应的语言包。

1.轻松执行图片文本的OCR识别
//Initialize an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();

//Set the Image property by loading the image from file path location or an instance of MemoryStream
ocrEngine.Image = ImageStream.FromFile(imageFile);

//Process the image
if (ocrEngine.Process())
{
    //Display the recognized text
    Console.WriteLine(ocrEngine.Text);
}

2. 对不同的语言进行识别
//Initialize an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();

//Set the Image property by loading the image from file path location or an instance of Stream
ocrEngine.Image = ImageStream.FromFile(imageFile);

//Clear the default language (English)
ocrEngine.LanguageContainer.Clear();

//Load the resources of the language from file path location or an instance of Stream
ocrEngine.LanguageContainer.AddLanguage(LanguageFactory.Load(@"LanguageResources.zip"));

//Process the image
if (ocrEngine.Process())
{
    //Display the recognized text
    Console.WriteLine(ocrEngine.Text);
}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat