void recognise() { WebClient wc = new WebClient(); wc.DownloadString("http://www.eregie.pub.ro/index.php?pgc=autentificare"); wc.Headers.Set("Cookie", wc.ResponseHeaders.Get("Set-Cookie")); wc.Headers.Set("Referer", "www.eregie.pub.ro/index.php?pgc=autentificare"); wc.Headers.Set("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); Bitmap captcha = (Bitmap)Bitmap.FromStream(wc.OpenRead("http://www.eregie.pub.ro/image_code.jpg")); //Bitmap captcha = (Bitmap)Bitmap.FromFile("E:/ocr_in/image_code" + nr_p++ + ".jpg"); picture_Original.Image = captcha; ERegieCaptchaOCR co = new ERegieCaptchaOCR(captcha); captcha = co.PregatesteImagine(); picture_Noiseless.Image = captcha; ERegieCaptchaOCR co2 = new ERegieCaptchaOCR(captcha); picture_Rotated.Image = co2.PregatesteImagine2(); List <Rectangle> chars = co2.CautaCaractere(); label1.Text = ""; for (int i = 0; i < chars.Count; i++) { char c = ocd.Identify(Form1.cropImage((Bitmap)(picture_Rotated.Image), chars[i])); label1.Text += (c >= 'a'?(char)(c - 32):c); Debug.WriteLine("{0} - {1}", c, chars[i].Width); } }
void GetChar() { if (pos == chars.Count) { //captcha = new Bitmap("e:/img.jpg"); WebClient wc = new WebClient(); wc.DownloadString("http://www.eregie.pub.ro/index.php?pgc=autentificare"); wc.Headers.Set("Cookie", wc.ResponseHeaders.Get("Set-Cookie")); wc.Headers.Set("Referer", "www.eregie.pub.ro/index.php?pgc=autentificare"); wc.Headers.Set("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); //wc.DownloadFile("http://www.eregie.pub.ro/image_code.jpg", "E:/captcha.jpg"); //return; captcha = (Bitmap)Bitmap.FromStream(wc.OpenRead("http://www.eregie.pub.ro/image_code.jpg")); pictureb_Preview.Image = captcha; //return; ERegieCaptchaOCR co = new ERegieCaptchaOCR(captcha); captcha = co.PregatesteImagine(); chars = co.CautaCaractere(); pos = 0; nr_poza++; } car = cropImage(captcha, chars[pos++]); pictureb_Preview.Image = car; }