3
下面是我測試Tesseract性能的非常簡單的程序。我得到的結果並不像預期的那樣,雖然圖片是高質量和非常清晰的截圖(不是複雜的顏色圖片)。請看看我的代碼和下面的結果。我不確定我是否做錯了或者Tesseract引擎無法處理這個問題?Tesseract OCR:非常不準確的結果
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);
}
}
}
如果您只有文本的圖片,tesseract應該能夠處理此問題。我用它不是作爲dll,而是作爲外部程序來解決驗證碼,我先用代碼編輯,它工作得很好。 –