2016-06-13 179 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以獲得更好的結果。