开发人员可以利用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);
}