コード例 #1
0
        public void on_new_screenshot(object sender, FileSystemEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                Task.Factory.StartNew(() =>
                {
                    upload_image(e.FullPath);
                });

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    lbl_report.Content = "New screenshot read...";
                    btn_report.IsEnabled = false;
                    found_mt = null;
                }));

                MapTempest mt = OCR.Image.read_map_tempest(e.FullPath, listview_maps.Items.Cast<Map>().ToList());

                Console.WriteLine(String.Format("Map name: {0}", mt.map));
                Console.WriteLine(String.Format("Tempest name: {0}", mt.tempest.name));
                bool do_vote = false;

                if (do_vote && mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) {
                    update_label_d(lbl_report, "Reporting {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                    bool res = vote(mt.map, mt.tempest.prefix, mt.tempest.suffix).Result;
                    if (res) {
                        Console.WriteLine("Successfully sent tempest data!");
                        update_label_d(lbl_report, "Reported {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                        update_tempests();
                    } else {
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            lbl_report.Content = "Error reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix;
                        }));
                    }
                } else {
                    update_label_d(lbl_report, "NOT reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix);
                    found_mt = mt;
                    if (mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) {
                        found_mt = null;
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (found_mt != null) {
                            btn_report.IsEnabled = false;
                        } else {
                            btn_report.IsEnabled = true;
                        }
                    }));
                }
            });
        }
コード例 #2
0
        public MapTempest get_map_tempest(List <KeyValuePair <string, string> > map_images, List <KeyValuePair <string, string> > tempest_images)
        {
            var mt = new MapTempest
            {
                map     = "???",
                tempest = new Tempest
                {
                    name   = "???",
                    prefix = "none",
                    suffix = "none",
                    votes  = 0
                }
            };

            foreach (KeyValuePair <string, string> kv in map_images)
            {
                if (mt.map != "???")
                {
                    /* Stop searching if we've already found a map match */
                    break;
                }

                update_label_d(lbl_report, "Reading {0} Map image", kv.Key);
                string text = get_text(kv.Value).ToLower().Trim();
                Console.WriteLine(String.Format("{0}: '{1}'", kv.Key, text));
                update_label_d(lbl_report, "Read {0} Map image ({1})", kv.Key, text);
                foreach (Map map in listview_maps.Items)
                {
                    string mapname = map.name.Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} to {1}", text, mapname);
                    if (text.Contains(mapname))
                    {
                        update_label_d(lbl_report, "Setting map to {0}", mapname);
                        mt.map = map.name;
                        break;
                    }
                }
            }

            List <FuzzyStringComparisonOptions> fuzzystringoptions = new List <FuzzyStringComparisonOptions>
            {
                FuzzyStringComparisonOptions.UseLevenshteinDistance,
            };

            FuzzyStringComparisonTolerance tolerance = FuzzyStringComparisonTolerance.Strong;

            List <string> tempest_texts = new List <string>();

            foreach (KeyValuePair <string, string> kv in tempest_images)
            {
                if (mt.tempest.suffix != "none" && mt.tempest.prefix != "none")
                {
                    /* Stop searching if we've already found a two tempests */
                    break;
                }

                update_label_d(lbl_report, "Reading {0} Tempest image", kv.Key);
                string text_raw = get_text(kv.Value).ToLower().Trim();
                tempest_texts.Add(text_raw);
                string text = text_raw.Replace(" ", "");

                update_label_d(lbl_report, "Read {0} Tempest image ({1})", kv.Key, text_raw);
                foreach (KeyValuePair <string, string> tempest_kv in tempest_affixes.prefixes)
                {
                    if (mt.tempest.prefix != "none")
                    {
                        break;
                    }
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} '{1}' with prefix {2}", kv.Key, text, affix);
                    if (text.Contains(affix))
                    {
                        update_label_d(lbl_report, "Setting prefix to {0}", affix);
                        mt.tempest.prefix = tempest_kv.Key;
                        break;
                    }
                }

                foreach (KeyValuePair <string, string> tempest_kv in tempest_affixes.suffixes)
                {
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} '{1}' with suffix {2}", kv.Key, text, affix);
                    if (text.Contains(affix))
                    {
                        update_label_d(lbl_report, "Setting suffix to {0}", affix);
                        mt.tempest.suffix = tempest_kv.Key;
                        break;
                    }
                }
            }

            foreach (string text_raw in tempest_texts)
            {
                if (mt.tempest.suffix != "none" && mt.tempest.prefix != "none")
                {
                    /* Stop searching if we've already found a two tempests */
                    break;
                }

                foreach (KeyValuePair <string, string> tempest_kv in tempest_affixes.prefixes)
                {
                    if (mt.tempest.prefix != "none")
                    {
                        break;
                    }
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');

                    foreach (string str in text_raw.Split(' '))
                    {
                        update_label_d(lbl_report, "Fuzzy comparing {0} with {1}", affix, str);
                        if (str.ApproximatelyEquals(affix, fuzzystringoptions, tolerance))
                        {
                            update_label_d(lbl_report, "Setting prefix to {0}", affix);
                            Console.WriteLine(String.Format("'{0}' matched '{1}'", str, affix));
                            mt.tempest.prefix = tempest_kv.Key;
                            break;
                        }
                    }
                }

                foreach (KeyValuePair <string, string> tempest_kv in tempest_affixes.suffixes)
                {
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');

                    foreach (string str in text_raw.Split(' '))
                    {
                        update_label_d(lbl_report, "Fuzzy comparing {0} with {1}", affix, str);
                        if (str.ApproximatelyEquals(affix, fuzzystringoptions, tolerance))
                        {
                            update_label_d(lbl_report, "Setting prefix to {0}", affix);
                            Console.WriteLine(String.Format("'{0}' matched '{1}'", str, affix));
                            mt.tempest.prefix = tempest_kv.Key;
                            break;
                        }
                    }
                }
            }

            mt.tempest.name = mt.tempest.prefix + " Tempest Of " + mt.tempest.suffix;

            update_label_d(lbl_report, "Done looping!");

            return(mt);
        }
コード例 #3
0
        public MapTempest get_map_tempest(List<KeyValuePair<string, string>> map_images, List<KeyValuePair<string, string>> tempest_images)
        {
            var mt = new MapTempest
            {
                map = "???",
                tempest = new Tempest
                {
                    name = "???",
                    prefix = "none",
                    suffix = "none",
                    votes = 0
                }
            };

            foreach (KeyValuePair<string, string> kv in map_images) {
                if (mt.map != "???") {
                    /* Stop searching if we've already found a map match */
                    break;
                }

                update_label_d(lbl_report, "Reading {0} Map image", kv.Key);
                string text = get_text(kv.Value).ToLower().Trim();
                Console.WriteLine(String.Format("{0}: '{1}'", kv.Key, text));
                update_label_d(lbl_report, "Read {0} Map image ({1})", kv.Key, text);
                foreach (Map map in listview_maps.Items) {
                    string mapname = map.name.Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} to {1}", text, mapname);
                    if (text.Contains(mapname)) {
                        update_label_d(lbl_report, "Setting map to {0}", mapname);
                        mt.map = map.name;
                        break;
                    }
                }
            }

            List<FuzzyStringComparisonOptions> fuzzystringoptions = new List<FuzzyStringComparisonOptions>
            {
                FuzzyStringComparisonOptions.UseLevenshteinDistance,
            };

            FuzzyStringComparisonTolerance tolerance = FuzzyStringComparisonTolerance.Strong;

            List<string> tempest_texts = new List<string>();

            foreach (KeyValuePair<string, string> kv in tempest_images) {
                if (mt.tempest.suffix != "none" && mt.tempest.prefix != "none") {
                    /* Stop searching if we've already found a two tempests */
                    break;
                }

                update_label_d(lbl_report, "Reading {0} Tempest image", kv.Key);
                string text_raw = get_text(kv.Value).ToLower().Trim();
                tempest_texts.Add(text_raw);
                string text = text_raw.Replace(" ", "");

                update_label_d(lbl_report, "Read {0} Tempest image ({1})", kv.Key, text_raw);
                foreach (KeyValuePair<string, string> tempest_kv in tempest_affixes.prefixes) {
                    if (mt.tempest.prefix != "none") {
                        break;
                    }
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} '{1}' with prefix {2}", kv.Key, text, affix);
                    if (text.Contains(affix)) {
                        update_label_d(lbl_report, "Setting prefix to {0}", affix);
                        mt.tempest.prefix = tempest_kv.Key;
                        break;
                    }
                }

                foreach (KeyValuePair<string, string> tempest_kv in tempest_affixes.suffixes) {
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');
                    update_label_d(lbl_report, "Comparing {0} '{1}' with suffix {2}", kv.Key, text, affix);
                    if (text.Contains(affix)) {
                        update_label_d(lbl_report, "Setting suffix to {0}", affix);
                        mt.tempest.suffix = tempest_kv.Key;
                        break;
                    }
                }
            }

            foreach (string text_raw in tempest_texts) {
                if (mt.tempest.suffix != "none" && mt.tempest.prefix != "none") {
                    /* Stop searching if we've already found a two tempests */
                    break;
                }

                foreach (KeyValuePair<string, string> tempest_kv in tempest_affixes.prefixes) {
                    if (mt.tempest.prefix != "none") {
                        break;
                    }
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');

                    foreach (string str in text_raw.Split(' ')) {
                        update_label_d(lbl_report, "Fuzzy comparing {0} with {1}", affix, str);
                        if (str.ApproximatelyEquals(affix, fuzzystringoptions, tolerance)) {
                            update_label_d(lbl_report, "Setting prefix to {0}", affix);
                            Console.WriteLine(String.Format("'{0}' matched '{1}'", str, affix));
                            mt.tempest.prefix = tempest_kv.Key;
                            break;
                        }
                    }
                }

                foreach (KeyValuePair<string, string> tempest_kv in tempest_affixes.suffixes) {
                    string affix = tempest_kv.Key.ToLower().Replace('_', ' ');

                    foreach (string str in text_raw.Split(' ')) {
                        update_label_d(lbl_report, "Fuzzy comparing {0} with {1}", affix, str);
                        if (str.ApproximatelyEquals(affix, fuzzystringoptions, tolerance)) {
                            update_label_d(lbl_report, "Setting prefix to {0}", affix);
                            Console.WriteLine(String.Format("'{0}' matched '{1}'", str, affix));
                            mt.tempest.prefix = tempest_kv.Key;
                            break;
                        }
                    }
                }
            }

            mt.tempest.name = mt.tempest.prefix + " Tempest Of " + mt.tempest.suffix;

            update_label_d(lbl_report, "Done looping!");

            return mt;
        }
コード例 #4
0
        public void on_new_screenshot(object sender, FileSystemEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                Task.Factory.StartNew(() =>
                {
                    upload_image(e.FullPath);
                });
                string map_path, tempest_path;
                string map_format_path, tempest_format_path;

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    lbl_report.Content   = "New screenshot read...";
                    btn_report.IsEnabled = false;
                    found_mt             = null;
                }));

                Bitmap img     = new Bitmap(e.FullPath);
                var img_width  = img.Width;
                var img_height = img.Height;

                var crop_data = new OCR.CropData
                {
                    map_from     = new Tuple <int, int>((int)(img_width * 0.85), 0),
                    map_to       = new Tuple <int, int>(img_width, (int)(img_height * 0.15)),
                    tempest_from = new Tuple <int, int>((int)(img_width * 0.85), (int)(img_height * 0.10)),
                    tempest_to   = new Tuple <int, int>(img_width, (int)(img_height * 0.45)),
                };

                foreach (var cd in OCR.CropData.resolutions)
                {
                    if (img_width == cd.Key.Item1 && img_height == cd.Key.Item2)
                    {
                        crop_data = cd.Value;
                        break;
                    }
                }

                try {
                    map_path            = Path.Combine(exe_dir, "map.png");
                    tempest_path        = Path.Combine(exe_dir, "tempest.png");
                    map_format_path     = Path.Combine(exe_dir, "map-{0}.png");
                    tempest_format_path = Path.Combine(exe_dir, "tempest-{0}.png");
                } catch (Exception ex) {
                    Console.WriteLine("Something went wrong while combining paths. {0}", ex.Message);
                    return;
                }

                update_label_d(lbl_report, "Cropping images");
                OCR.Image.crop(e.FullPath, map_path, crop_data.map_from, crop_data.map_to);
                OCR.Image.crop(e.FullPath, tempest_path, crop_data.tempest_from, crop_data.tempest_to);

                update_label_d(lbl_report, "Applying filters to images");
                var map_images     = OCR.Image.apply_filters(map_path, map_format_path);
                var tempest_images = OCR.Image.apply_filters(tempest_path, tempest_format_path);

                MapTempest mt = get_map_tempest(map_images, tempest_images);
                Console.WriteLine(String.Format("Map name: {0}", mt.map));
                Console.WriteLine(String.Format("Tempest name: {0}", mt.tempest.name));
                bool do_vote = false;

                if (do_vote && mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none"))
                {
                    update_label_d(lbl_report, "Reporting {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                    bool res = vote(mt.map, mt.tempest.prefix, mt.tempest.suffix).Result;
                    if (res)
                    {
                        Console.WriteLine("Successfully sent tempest data!");
                        update_label_d(lbl_report, "Reported {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                        update_tempests();
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            lbl_report.Content = "Error reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix;
                        }));
                    }
                }
                else
                {
                    update_label_d(lbl_report, "NOT reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix);
                    found_mt = mt;
                    if (mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none"))
                    {
                        found_mt = null;
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (found_mt != null)
                        {
                            btn_report.IsEnabled = false;
                        }
                        else
                        {
                            btn_report.IsEnabled = true;
                        }
                    }));
                }
            });
        }
コード例 #5
0
        public void on_new_screenshot(object sender, FileSystemEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                Task.Factory.StartNew(() =>
                {
                    upload_image(e.FullPath);
                });
                string map_path, tempest_path;
                string map_format_path, tempest_format_path;

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    lbl_report.Content = "New screenshot read...";
                    btn_report.IsEnabled = false;
                    found_mt = null;
                }));

                Bitmap img = new Bitmap(e.FullPath);
                var img_width = img.Width;
                var img_height = img.Height;

                var crop_data = new OCR.CropData
                {
                    map_from = new Tuple<int, int>((int)(img_width * 0.85), 0),
                    map_to = new Tuple<int, int>(img_width, (int)(img_height * 0.15)),
                    tempest_from = new Tuple<int, int>((int)(img_width * 0.85), (int)(img_height * 0.10)),
                    tempest_to = new Tuple<int, int>(img_width, (int)(img_height * 0.45)),
                };

                foreach (var cd in OCR.CropData.resolutions) {
                    if (img_width == cd.Key.Item1 && img_height == cd.Key.Item2) {
                        crop_data = cd.Value;
                        break;
                    }
                }

                try {
                    map_path = Path.Combine(exe_dir, "map.png");
                    tempest_path = Path.Combine(exe_dir, "tempest.png");
                    map_format_path = Path.Combine(exe_dir, "map-{0}.png");
                    tempest_format_path = Path.Combine(exe_dir, "tempest-{0}.png");
                } catch (Exception ex) {
                    Console.WriteLine("Something went wrong while combining paths. {0}", ex.Message);
                    return;
                }

                update_label_d(lbl_report, "Cropping images");
                OCR.Image.crop(e.FullPath, map_path, crop_data.map_from, crop_data.map_to);
                OCR.Image.crop(e.FullPath, tempest_path, crop_data.tempest_from, crop_data.tempest_to);

                update_label_d(lbl_report, "Applying filters to images");
                var map_images = OCR.Image.apply_filters(map_path, map_format_path);
                var tempest_images = OCR.Image.apply_filters(tempest_path, tempest_format_path);

                MapTempest mt = get_map_tempest(map_images, tempest_images);
                Console.WriteLine(String.Format("Map name: {0}", mt.map));
                Console.WriteLine(String.Format("Tempest name: {0}", mt.tempest.name));
                bool do_vote = false;

                if (do_vote && mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) {
                    update_label_d(lbl_report, "Reporting {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                    bool res = vote(mt.map, mt.tempest.prefix, mt.tempest.suffix).Result;
                    if (res) {
                        Console.WriteLine("Successfully sent tempest data!");
                        update_label_d(lbl_report, "Reported {0}, {1} tempest of {2}", mt.map, mt.tempest.prefix, mt.tempest.suffix);
                        update_tempests();
                    } else {
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            lbl_report.Content = "Error reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix;
                        }));
                    }
                } else {
                    update_label_d(lbl_report, "NOT reporting " + mt.map + ", " + mt.tempest.prefix + " tempest of " + mt.tempest.suffix);
                    found_mt = mt;
                    if (mt.map != "???" && (mt.tempest.prefix != "none" || mt.tempest.suffix == "none")) {
                        found_mt = null;
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (found_mt != null) {
                            btn_report.IsEnabled = false;
                        } else {
                            btn_report.IsEnabled = true;
                        }
                    }));
                }
            });
        }