我正在尝试运行tessnet,图片只包含Numbers,但它总是给我“〜”因此,我不明白为什么...... 这是代码:
private void button1_Click(object sender, EventArgs e)
{
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.SetVariable("tessedit_char_whitelist", "0123456789");
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
代码有什么问题?我该如何解决?