如何将OCR设置为只识别数字
发布网友
发布时间:2022-05-10 23:30
我来回答
共1个回答
热心网友
时间:2023-10-07 08:42
下面的代码主要讲述了怎么设置OCR只对数字进行识别,具体如下:
using System;
using Vintasoft.Imaging;
using Vintasoft.Imaging.Ocr;
using Vintasoft.Imaging.Ocr.Results;
using Vintasoft.Imaging.Ocr.Tesseract;
class TesseractOcrSetVariableExample
{
// Required assemblies to run this code:
// Vintasoft.Imaging.dll, Vintasoft.Imaging.Ocr.dll, Vintasoft.Imaging.Ocr.Tesseract.dll
public static void OcrImageWithDigits(string filename)
{
// load image(s)
ImageCollection images = new ImageCollection();
images.Add(filename);
Console.WriteLine("Create Tesseract OCR engine...");
using (TesseractOcr tesseractOcr = new TesseractOcr())
{
Console.WriteLine("Initialize OCR engine...");
tesseractOcr.Init(new OcrEngineSettings(OcrLanguage.English));
// set white list
tesseractOcr.SetVariable(
"tessedit_char_whitelist", "01234567890");
// foreach image
foreach (VintasoftImage image in images)
{
Console.WriteLine("Recognize the image...");
OcrPage page = tesseractOcr.Recognize(image);
Console.WriteLine("Page Text:");
Console.WriteLine(page.GetText());
Console.WriteLine();
}
// shutdown OCR engine
tesseractOcr.Shutdown();
}
// free resources
images.ClearAndDisposeItems();
images.Dispose();
}
}