Exemple #1
0
        private static string ScanEnhancementMaterialName(Bitmap bm)
        {
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            // Analyze
            string name = Regex.Replace(Scraper.AnalyzeText(n).ToLower(), @"[\W]", string.Empty);

            name = Scraper.FindClosestMaterialName(name, 3);
            n.Dispose();

            return(name);
        }
        public static string ScanMaterialName(InventorySection section, out Bitmap nameplate)
        {
            // Grab item name on right
            var refWidth  = 1280.0;
            var refHeight = Navigation.GetAspectRatio() == new Size(16, 9) ? 720.0 : 800.0;

            var width  = Navigation.GetWidth();
            var height = Navigation.GetHeight();

            var reference = new Rectangle(872, 80, 327, 37);

            // Nameplate is in the same place in 16:9 and 16:10
            var region = new RECT(
                Left:   (int)(reference.Left / refWidth * width),
                Top:    (int)(reference.Top / refHeight * height),
                Right:  (int)(reference.Right / refWidth * width),
                Bottom: (int)(reference.Bottom / refHeight * height));

            Bitmap bm = Navigation.CaptureRegion(region);

            nameplate = (Bitmap)bm.Clone();

            // Alter Image
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            string text = Scraper.AnalyzeText(n);

            text = Regex.Replace(text, @"[\W]", string.Empty).ToLower();

            //UI
            n.Dispose();
            bm.Dispose();

            if (section == InventorySection.CharacterDevelopmentItems)
            {
                return(Scraper.FindClosestDevelopmentName(text));
            }

            if (section == InventorySection.Materials)
            {
                return(Scraper.FindClosestMaterialName(text));
            }

            return(null);
        }
        public static int ScanMaterialCount(Rectangle rectangle, out Bitmap quantity)
        {
            var region = new RECT(
                Left: rectangle.X,
                Top: (int)(rectangle.Y + (0.8 * rectangle.Height)),                 // Only get the bottom of inventory item
                Right: rectangle.Right,
                Bottom: rectangle.Bottom + 10);

            using (Bitmap bm = Navigation.CaptureRegion(region))
            {
                quantity = (Bitmap)bm.Clone();

                using (Bitmap rescaled = Scraper.ResizeImage(bm, (int)(bm.Width * 3), (int)(bm.Height * 3)))
                {
                    Bitmap copy = (Bitmap)rescaled.Clone();
                    Scraper.SetGamma(0.7, 0.7, 0.7, ref copy);
                    // Image Processing
                    Bitmap n = Scraper.ConvertToGrayscale(copy);
                    Scraper.SetContrast(65, ref n);                     // Setting a high contrast seems to be better than thresholding
                    //Scraper.SetThreshold(165, ref n);

                    string old_text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleWord).Trim().ToLower();

                    // Might be worth it to train some more numbers
                    var cleaned = old_text.Replace("mm", "111").Replace("m", "11").Replace("nn", "11").Replace("n", "1");                     // Tesseract struggles with 1's so close together because of font
                    cleaned = cleaned.Replace("a", "4");
                    cleaned = cleaned.Replace("e", "1");
                    //old_text = old_text.Replace("b", "8");
                    //old_text = old_text.Replace("+", "4");

                    cleaned = Regex.Replace(cleaned, @"[^0-9]", string.Empty);

                    _ = int.TryParse(cleaned, out int count);

                    Debug.WriteLine($"{old_text} -> {cleaned} -> {count}");

                    //if (count > 3000 || count == 0)
                    //{
                    //	//Navigation.DisplayBitmap(n);
                    //}
                    copy.Dispose();
                    n.Dispose();
                    return(count);
                }
            }
        }
        public static string ScanName(Bitmap bm)
        {
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            // Analyze
            string text = Regex.Replace(Scraper.AnalyzeText(n).ToLower(), @"[\W]", string.Empty);

            text = Scraper.FindClosestWeapon(text);

            n.Dispose();

            // Check in Dictionary
            return(text);
        }
        public static string ScanMainCharacterName()
        {
            var xReference = 1280.0;
            var yReference = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yReference = 800.0;
            }

            RECT region = new RECT(
                Left:   (int)(185 / xReference * Navigation.GetWidth()),
                Top:    (int)(26 / yReference * Navigation.GetHeight()),
                Right:  (int)(460 / xReference * Navigation.GetWidth()),
                Bottom: (int)(60 / yReference * Navigation.GetHeight()));

            Bitmap nameBitmap = Navigation.CaptureRegion(region);

            //Image Operations
            Scraper.SetGamma(0.2, 0.2, 0.2, ref nameBitmap);
            Scraper.SetInvert(ref nameBitmap);
            Bitmap n = Scraper.ConvertToGrayscale(nameBitmap);

            UserInterface.SetNavigation_Image(nameBitmap);

            string text = Scraper.AnalyzeText(n).Trim();

            if (text != "")
            {
                // Only keep a-Z and 0-9
                text = Regex.Replace(text, @"[\W_]", string.Empty).ToLower();

                // Only keep text up until first space
                text = Regex.Replace(text, @"\s+\w*", string.Empty);

                UserInterface.SetMainCharacterName(text);
            }
            else
            {
                UserInterface.AddError(text);
            }
            n.Dispose();
            nameBitmap.Dispose();
            return(text);
        }