1
我試圖運行tessnet,圖像只包含數字,但它總是給我「〜」作爲結果,我不明白爲什麼... 這裏是代碼:tessnet c#給出錯誤的結果
private void button1_Click(object sender, EventArgs e)
{
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "");
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倍),然後查看是否給出了任何結果。 – Charleh 2014-09-05 14:34:00
謝謝你的回答,試了一下,它不起作用 – user52713 2014-09-05 14:37:58
你試過[訓練](http://blog.cedric.ws/how-to-train-tesseract-301)tesseract與你的字體? – 2014-09-05 14:44:23