示例#1
0
        public override DecoderItem Decode(byte[] input, VisualDecoderSettings settings)
        {
            var result   = new DecoderItem();
            var language = settings.OCRLanguage.ToString();

            //use eng if the user dont know the language
            if (language.Equals(VisualDecoderSettings.OCRLanguages.unkown.ToString()))
            {
                language = VisualDecoderSettings.OCRLanguages.eng.ToString();
            }

            using (var ocr = new tessnet2.Tesseract()){
                try
                {
                    ocr.Init(TessractData, language, settings.NumericMode);
                    List <tessnet2.Word> r1 = ocr.DoOCR(ByteArrayToImage(input), Rectangle.Empty);

                    //aggregate resultTest
                    string resultText = "";
                    int    lc         = tessnet2.Tesseract.LineCount(r1);
                    for (int i = 0; i < lc; i++)
                    {
                        resultText += tessnet2.Tesseract.GetLineText(r1, i) + "\n";
                    }

                    //fill result
                    result.CodePayload          = resultText;
                    result.CodeType             = "none";
                    result.BitmapWithMarkedCode = input;
                    ocr.Clear();
                }
                catch (Exception) // well, the ocr lib sucks... it sometimes trows memory leaks.
                                  // But it is the best opensource lib available.
                {
                }
            }
            return(result);
        }
示例#2
0
        private static async Task <string> CrackCaptcha(HttpClient client)
        {
            //System.Diagnostics.Debugger.Break();
            try
            {
                Bitmap captchaBitmap = await LoadPicture(client, "https://signup.leagueoflegends.com/de/signup/captcha/");

                PrepareCaptcha(captchaBitmap);
                captchaBitmap.Save("captcha.png");

                string result = "";

                using (tessnet2.Tesseract ocr = new tessnet2.Tesseract())
                {
                    ocr.Init(Directory.GetCurrentDirectory() + @"\tessdata\", "eng", false);
                    ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

                    List <tessnet2.Word> wlist = ocr.DoOCR(captchaBitmap, Rectangle.Empty);
                    foreach (tessnet2.Word w in wlist)
                    {
                        result += w.Text;
                    }

                    ocr.Clear();
                    ocr.Dispose();
                    wlist.Clear();

                    return(result);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return("ERROR");
        }