Beispiel #1
0
        //Room detection algorithm
        public int roomDetect(Awesomium.Windows.Forms.WebControl wb, int bw)
        {
            int room = 0;
            //Take screenshot of region, store to temporary bitmap
            Bitmap   bmpScreenShot = new Bitmap(17, 36);
            Graphics gfx           = Graphics.FromImage((Image)bmpScreenShot);
            Point    ctrlp         = wb.PointToScreen(Point.Empty);

            try { gfx.CopyFromScreen(ctrlp.X, ctrlp.Y, 0, 0, new Size(17, 36)); }
            catch { return(-1); }

            bmpScreenShot.Save(temp);

            //load jungle cruise bitmap
            Bitmap fw = MyVMK_Pal.Properties.Resources.jungle_cruise_rc;

            //Check to see if is equal
            if (IsEqual())
            {
                room = 2;
            }
            //Delete temporary file
            if (File.Exists(temp))
            {
                File.Delete(temp);
            }
            //Return room id
            return(room);
        }
Beispiel #2
0
        public int readScore(Awesomium.Windows.Forms.WebControl clientBrowser, int gameID)
        {
            int score = 0;

            int[] size      = new int[2];
            int   fontColor = 255;

            switch (gameID)
            {
            case 1:
                //Fireworks
                break;

            case 2:
                //Jungle Cruise
                size[0]   = 94;
                size[1]   = 36;
                fontColor = 239;
                break;

            default:
                //Something went wrong
                return(0);
            }

            //Take screenshot of region, store to temporary bitmap
            Bitmap   scoreShot = new Bitmap(size[0], size[1]);
            Graphics gfx       = Graphics.FromImage((Image)scoreShot);
            Point    ctrlp     = clientBrowser.PointToScreen(Point.Empty);

            try { gfx.CopyFromScreen(ctrlp.X, ctrlp.Y, 0, 0, new Size(size[0], size[1])); }
            catch { return(-1); }

            //Replace everything except characters with black
            for (int x = 0; x < scoreShot.Width; x++)
            {
                for (int y = 0; y < scoreShot.Height; y++)
                {
                    Color gotColor = scoreShot.GetPixel(x, y);
                    if (gotColor != Color.FromArgb(fontColor, fontColor, fontColor))
                    {
                        scoreShot.SetPixel(x, y, Color.Black);
                    }
                }
            }

            //Use tessnet2 to extract score via OCR

            Ocr ocr = new Ocr();
            List <tessnet2.Word> res = new List <tessnet2.Word>();

            using (Bitmap bmp = scoreShot)
            {
                tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
                tessocr.Init(null, "eng", false);
                tessocr.GetThresholdedImage(bmp, Rectangle.Empty).Save("c:\\x\\" + Guid.NewGuid().ToString() + ".bmp");
                // Tessdata directory must be in the same directory as this exe
                res = ocr.DoOCRNormal(bmp, "eng");
            }

            foreach (tessnet2.Word word in res)
            {
                bool isNumeric = int.TryParse(word.Text, out score);
                if (!isNumeric)
                {
                    score = 0;
                }
            }

            //Return the score value
            return(score);
        }