Tessnet2只返回一个字符

本文关键字:一个 字符 返回 Tessnet2 | 更新日期: 2023-09-27 18:12:36

我正在编写一个应用程序,我想读取图像并提取文本。为了测试猪栏,我传递了一个有6个字符的图像。这是我的代码。

Bitmap image = new Bitmap("eurotext.tif");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "abcdefghijklmopqrstuvwxyz0123456789"); // If digit only
ocr.Init(null, "eng", false); // To use correct tessdata
List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
foreach (tessnet2.Word word in result)
Console.WriteLine("{0} : {1}", word.Confidence, word.Text);

结果是100: ~

第二次运行时返回:

100: -

请帮助! !由于

Tessnet2只返回一个字符

尝试更大的图片。当我开始使用tessnet2时,我得到了几次"~"。当我使用更大的图片(Textsize应该大于12)后,程序工作得很好。

要放大图片并尝试不同的大小,您可以使用跟踪条和以下代码:

c#

        Bitmap originalImage = new Bitmap(imagePath, true);
        double needdedHeigth = Convert.ToDouble(trackbar1.Value);
        double faktor = needdedHeigth / (double)originalImage.Height;
        int newWidth = Convert.ToInt32(faktor * (double)originalImage.Width);
        Bitmap ORCImage = new Bitmap(originalImage,newWidth,Convert.ToInt32(needdedHeigth));

在'DoOCR()'方法中使用' OCRImage'位图