【问题标题】:tessnet c# giving wrong resultstessnet c#给出错误的结果
【发布时间】:2014-09-05 14:23:41
【问题描述】:

我正在尝试运行 tessnet,图像仅包含数字,但结果总是给我“~”,我不明白为什么...... 代码如下:

private void button1_Click(object sender, EventArgs e)
        {
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.SetVariable("tessedit_char_whitelist", "0123456789");
            ocr.Init(@"C:\Users\Poox\Documents\Visual Studio 2013\Projects\testCaptcha\tessdata", "fra", false);
            Bitmap imgBit = new Bitmap(getImage());
           //Changing the colors of the picutre, making it easier to read, number in black and a white background:
            Color good = new Color();
            good = imgBit.GetPixel(44, 19);//the color of the numbers
            int x = 0, y = 0, mx = 100, my = 42;
            for (x = 0; x < mx; x++)
            {
                for (y = 0; y < my; y++)
                {
                    if (imgBit.GetPixel(x, y).Equals(good))
                    {
                        //a number
                        imgBit.SetPixel(x, y, Color.Black);
                    }
                    else { imgBit.SetPixel(x, y, Color.White); }//the background
                }
            }
            imgBit.Save("image2.bmp");
            //OCR; 
            String captcha = "";
            List<tessnet2.Word> result = ocr.DoOCR(imgBit, Rectangle.Empty);
            imgBit.Dispose();
            foreach (tessnet2.Word word in result)
            {
                captcha = captcha + "" + word.Text;
            } MessageBox.Show(captcha);
       }

        public Image getImage()
        {
            Image img = null;
            WebClient client = new WebClient();
            try
            {
                img = Image.FromStream(client.OpenRead("- Image Link - "));
            }catch { }
            client.Dispose();
            client = null;
            return img;
        }

我从链接中获取图片,使其更“清晰”,然后将其传递给 OCR,但就像我说的,它没有正确读取它,它给了我〜结果.. 。 总是! 这是我更改颜色后图片的样子,以使其更明显: Image

代码可能有什么问题?我该如何解决?

【问题讨论】:

  • 可能是您的图像太小 - OCR 通常需要适当的分辨率(大多数 OCRd 文档往往是扫描的,因此需要 300DPI 或更高)。您可能想尝试将图像重新缩放到原来的几倍(先尝试放大 10 倍),看看是否有任何结果。
  • 谢谢解答,试过了,还是不行
  • 你用你的字体试过trainingtesseract吗?

标签: c# ocr


【解决方案1】:

所以这个问题与 Charleh 在 cmets 中所说的有关。图片太小了。我拍摄了您的图像并将其调整为 300x300 dpi 并使用插值(重新采样)。然后我将其转换为 1BPP,因为您的原始图像是使用 AutoBinarize 的 32BPP 并将其保存出来。

你可以在这里看到最终的图像:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 2020-04-01
    • 1970-01-01
    • 2011-11-15
    • 2019-02-06
    相关资源
    最近更新 更多