tessnet c#给出错误的结果
问题描述:
我试图运行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