Beispiel #1
0
        public static List <Captcha> GetRecognizedCaptchas(int limit = -1)
        {
            var files = Directory.EnumerateFiles(Path);
            var res   = new List <Captcha>();

            foreach (var filePath in files)
            {
                if (Regex.IsMatch(filePath, @"\.res$"))
                {
                    var name = filePath.Replace(".res", "").Replace(Path, "");
                    res.Add(Captcha.FromLibrary(name));
                }
                if (limit != -1 && res.Count >= limit)
                {
                    break;
                }
            }
            return(res);
        }
Beispiel #2
0
        private static Captcha _getCaptchaSource()
        {
            var res = new Captcha();

            using (var client = new WebClient())
            {
                // Or you can get the file content without saving it:
                var htmlCode = client.DownloadString("http://govnokod.ru/user/register");

                var re = new Regex("http://govnokod.ru/captcha/image\\?rand=(\\w+)", RegexOptions.IgnoreCase);

                var m = re.Match(htmlCode);
                if (m.Success)
                {
                    res.Source = m.Captures[0].Value;
                    res.Name   = m.Groups[1].Value;
                }
            }
            return(res);
        }
Beispiel #3
0
        private void _next()
        {
            try
            {
                _currentCaptcha = GKRegistration.GetNextCaptcha();
            }
            catch (Exception e)
            {
                Thread.Sleep(100);
                MessageBox.Show(e.Message, "Error");
                _next();
                return;
            }
            imagePanel.BackgroundImage       = _currentCaptcha.Image;
            imagePanel.BackgroundImageLayout = ImageLayout.Stretch;
            answerTextBox.Text = "";
            randLabel.Text     = _currentCaptcha.Name;

            var img = _currentCaptcha.Image;

            img = ImageHelper.Crop(img, new Rectangle(1, 1, img.Width - 2, img.Height - 2));
            img = ImageHelper.Binarize(img);
            img = ImageHelper.RemoveLines(img);

            var recognizer = new CaptchaRecognizer(_currentCaptcha.Image);
            var rects      = recognizer.SplitDigits();

            var drawArea = new Bitmap(img);

            hintImagePanel.BackgroundImage       = drawArea;
            hintImagePanel.BackgroundImageLayout = ImageLayout.Stretch;

            Graphics g   = Graphics.FromImage(drawArea);
            var      pen = new Pen(Brushes.Blue);

            foreach (var rect in rects)
            {
                g.DrawRectangle(pen, rect);
            }
        }