Example #1
0
        public static (Point point, Bitmap img) GetAnswer(Bitmap screen, int answerNum)
        {
            Rectangle rec = ANSWER_POS_DICT[answerNum];

            rec.X      = rec.X * screen.Width / BASE_WIDTH;
            rec.Y      = rec.Y * screen.Height / BASE_HEIGHT;
            rec.Width  = rec.Width * screen.Width / BASE_WIDTH;
            rec.Height = rec.Height * screen.Height / BASE_HEIGHT;

            Bitmap answerImg = QuizSolver.CropImage(screen, rec);

            answerImg.Save("C:\\TestWin32\\crop" + answerNum + ".png", ImageFormat.Png);


            // TODO: calculate point to click
            return(new Point(rec.X + rec.Width / 2, rec.Y + rec.Height / 2), answerImg);
        }
Example #2
0
        // The following methods should be private.

        public static string GetQuizPattern(Bitmap screen, int width, int height)
        {
            string pattern = String.Empty;
            double scale   = 0.8;

            Rectangle rec = new Rectangle((int)(400 * width / BASE_WIDTH),
                                          (int)(250 * height / BASE_HEIGHT),
                                          (int)(1200 * width / BASE_WIDTH),
                                          (int)(150 * height / BASE_HEIGHT));


            Bitmap questionImg = QuizSolver.CropImage(screen, rec);

            questionImg = ConvertToFormat(questionImg, PixelFormat.Format24bppRgb);
            questionImg = new ResizeBicubic((int)(questionImg.Width * scale), (int)(questionImg.Height * scale)).Apply(questionImg);


            DirectoryInfo d = new DirectoryInfo(CAPTCHA_POPUP_DIR); //Assuming Test is your Folder

            FileInfo[] Files = d.GetFiles();                        //Getting Text files

            foreach (FileInfo file in Files)
            {
                Bitmap template = new Bitmap(file.FullName);
                template = ConvertToFormat(template, PixelFormat.Format24bppRgb);
                // resize to match the source image
                template = new ResizeBicubic(template.Width * width / BASE_WIDTH, template.Height * height / BASE_HEIGHT).Apply(template);
                template = new ResizeBicubic((int)(template.Width * scale), (int)(template.Height * scale)).Apply(template);

                ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.87f);

                TemplateMatch[] matchings = tm.ProcessImage(questionImg, template);
                if (matchings.Length > 0)
                {
                    pattern += file.Name + " ";
                }
            }

            if (string.IsNullOrEmpty(pattern))
            {
                return(pattern);
            }

            if (pattern.Contains("water"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_WATER;
                }
                else
                {
                    pattern = ALL_WATER;
                }
            }
            else if (pattern.Contains("fire"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_FIRE;
                }
                else
                {
                    pattern = ALL_FIRE;
                }
            }
            else if (pattern.Contains("wind"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_WIND;
                }
                else
                {
                    pattern = ALL_WIND;
                }
            }
            else if (pattern.Contains("angelmon"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_ANGELMON;
                }
                else
                {
                    pattern = ANGELMON;
                }
            }
            else if (pattern.Contains("cairos"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_CAIROS;
                }
                else
                {
                    pattern = CAIROS;
                }
            }
            else if (pattern.Contains("boss"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_BOSS;
                }
                else
                {
                    pattern = BOSS;
                }
            }
            else if (pattern.Contains("ellia"))
            {
                if (pattern.Contains("excluding"))
                {
                    pattern = EXCLUDE_ELLIA;
                }
                else
                {
                    pattern = ELLIA;
                }
            }

            return(pattern);
        }