2016-06-13 246 views
3

下面是我测试Tesseract性能的非常简单的程序。我得到的结果并不像预期的那样,虽然图片是高质量和非常清晰的截图(不是复杂的颜色图片)。请看看我的代码和下面的结果。我不确定我是否做错了或者Tesseract引擎无法处理这个问题?Tesseract OCR:非常不准确的结果

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Drawing.Imaging; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using tessnet2; 

namespace ImageProcessTesting 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     int up_lef_x = 1075; 
     int up_lef_y = 0070; 

     int bo_rig_x = 1430; 
     int bo_rig_y = 0095; 

     int width = bo_rig_x - up_lef_x; 
     int height = bo_rig_y - up_lef_y; 

     var bmpScreenshot = new Bitmap(width, height, PixelFormat.Format32bppArgb); 
     var gfxScreenshot = Graphics.FromImage(bmpScreenshot); 

     gfxScreenshot.CopyFromScreen(
            1075, 
            0070, 
            0, 
            0, 
            Screen.PrimaryScreen.Bounds.Size, 
            CopyPixelOperation.SourceCopy); 

     // bmpScreenshot.Save("C:\\Users\\Exa\\Screenshot.png", ImageFormat.Png); 


     var image = bmpScreenshot; 
     var ocr = new Tesseract(); 
     ocr.Init(@"C:\Users\Exa\Desktop\tessdata", "eng", false); 
     var result = ocr.DoOCR(image, Rectangle.Empty); 
     string result_str = ""; 
     foreach (Word word in result) 
      result_str += word.Text; 
     MessageBox.Show(result_str); 

    } 
} 
} 
+0

如果您只有文本的图片,tesseract应该能够处理此问题。我用它不是作为dll,而是作为外部程序来解决验证码,我先用代码编辑,它工作得很好。 –

回答

0

96DPI屏幕截图是典型OCR不适合。如写在Tesseract wiki

有一个合理的准确性的最小文本大小。你必须考虑分辨率和点的大小。准确度下降到10pt x 300dpi以下,迅速低于8pt x 300dpi。快速检查是计算角色的x高度的像素。 (X高度是小写字母x的高度)。在10pt x 300dpi x高度通常约为20像素,尽管字体可能会有很大差异。在10像素的x高度下,准确结果的可能性非常小,低于大约8像素时,大部分文字将被“去除噪音”。

但是,如果您知道它的确切字体,您可以尝试重新训练tesseract以获得更好的结果。