From 5f6e7f0c6aa6c07016fb9a45a33de83f8878644b Mon Sep 17 00:00:00 2001 From: Charles Poitras Date: Fri, 8 Jul 2022 21:53:10 -0400 Subject: [PATCH] Level 4 decos, black bars, ignore updates (#36) * likely black bar removal, lvl4 deco * black bars checkbox in UI * ignore main app updates * fixes #34 by actually translating language * You can now add "invalid" skills * version bump & readme * fixed UTF-8 loading issue with symspellpy (thanks W-1252) --- .vscode/launch.json | 1 + PATCHNOTES.md | 28 +++++++-- README.md | 38 ++++++------ data/translations/eng.json | 8 ++- data/translations/fra.json | 14 +++-- data/versions.json | 6 +- images/slots/slot4.png | Bin 0 -> 2516 bytes src/__main__.py | 3 +- src/frame_extraction.py | 102 +++++++++++++++++++++++++++++-- src/resources.py | 45 +++++++++++++- src/tesseract/tesseract_utils.py | 14 ++--- src/ui/AskUpdate.py | 18 +++++- src/ui/MainWindow.py | 21 ++++++- src/ui/ParseRepairWindow.py | 17 +++++- src/updater/updater_utils.py | 49 +++++++-------- src/utils.py | 23 ++++--- 16 files changed, 292 insertions(+), 95 deletions(-) create mode 100644 images/slots/slot4.png diff --git a/.vscode/launch.json b/.vscode/launch.json index bbedf91..ca7f355 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Python: Current File", "type": "python", diff --git a/PATCHNOTES.md b/PATCHNOTES.md index 65f7913..629e11e 100644 --- a/PATCHNOTES.md +++ b/PATCHNOTES.md @@ -1,5 +1,25 @@ -# Patch Notes (Updated June 22nd 2022) -- 1.6 +# Patch Notes +- 1.7 (July 8th 2022) + - Added level 4 slot support (#35) + - Fixed restarting the app after setting a different game language (#34) + - You can now ignore an update + - You can now add invalid skills (or skills that are not in the list, don't come to me if the builder doesn't work) + - You can record in windowed mode (See next point) + - You can now let the app remove black bars from videos + - It is experimental. You should fix your recordings first if it doesn't work + - Black bars can be caused by not setting your TV size to 100% in the switch settings. + +# Older patch notes +- 1.6.2 (July 5th 2022) + - Fixed an issue with the creation of the config file + - `--reset` commandline option now takes into account `-a` and `-l` +- 1.6.1 (July 5th 2022) + - Tesseract location now goes through the entire list of OS-specific locations + - You can now set a custom tesseract location in the config (it has a higher priority) + - Added a few extra error messages + - New English Sunbreak skills and corrections are now bundled. + - The other languages use the english names as placeholders, sorry about that, feel free to submit the names. +- 1.6 (June 22nd 2022) - Added an app language dropdown - Version Checker automatically updates language files - Other updates (main app, skills and corrections) are still "on demand" when there is an update @@ -8,10 +28,6 @@ - Languages in language dropdowns should show up in the actual language - NOTE: They are probably wrong - Added a "Go to Set Searcher" button - - -# Older patch notes - - 1.5.3 (FEB 3rd 2022) - Updated where language packs are downloaded from, - Github changed where "raw" data was fetched from and broke "fresh" installs diff --git a/README.md b/README.md index 756e45a..7aa41e9 100644 --- a/README.md +++ b/README.md @@ -12,27 +12,16 @@ This repo contains code that will allow you to extract all of your charms in Mon It's called Utsushi's charm because I thought it would be funny to make a complementary "Utsushi's Armor Search System", but [this armor set searcher](https://mhrise.wiki-db.com/sim/?hl=en) exists. I might still try to port Athena's ASS for MHW to MHR, but for now this works for me. -# Patch Notes (Updated July 5th 2022) -The next non-bugfix version will have the option to ignore an update for those who don't care or don't have issues. Sorry for the double update in one day - -- 1.6.2 (July 5th 2022) - - Fixed an issue with the creation of the config file - - `--reset` commandline option now takes into account `-a` and `-l` -- 1.6.1 (July 5th 2022) - - Tesseract location now goes through the entire list of OS-specific locations - - You can now set a custom tesseract location in the config (it has a higher priority) - - Added a few extra error messages - - New English Sunbreak skills and corrections are now bundled. - - The other languages use the english names as placeholders, sorry about that, feel free to submit the names. -- 1.6 (June 22nd 2022) - - Added an app language dropdown - - Version Checker automatically updates language files - - Other updates (main app, skills and corrections) are still "on demand" when there is an update - - App and game language are now stored inside a config file - - Added a --reset cmd option to clear the config file - - Languages in language dropdowns should show up in the actual language - - NOTE: They are probably wrong - - Added a "Go to Set Searcher" button +# Patch Notes (Updated July 8th 2022) +- 1.7 (July 8th 2022) + - Added level 4 slot support (#35) + - Fixed restarting the app after setting a different game language (#34) + - You can now ignore an update + - You can now add invalid skills (or skills that are not in the list, don't come to me if the builder doesn't work) + - You can record in windowed mode (See next point) + - You can now let the app remove black bars from videos + - It is experimental. You should fix your recordings first if it doesn't work + - Black bars can be caused by not setting your TV size to 100% in the switch settings. The rest of the patch notes can be found [here](PATCHNOTES.md) @@ -124,6 +113,10 @@ Having translations for the instructions for other languages might be useful, bu - I see no reason other capture cards should not work - 1080p adds extra processing due to a downscaling step to 720p (20-30% slower) - I also tested using an Mclassic without any issues. +- Q: I record with a capture card but there are black bars + - 99% of the time this will be caused by not having the screen size set to 100% in the switch settings + - In the remaining cases, you should check your recorder settings. + - You can try using the "Remove black bars" feature. - Q: Does this Work for the PC version - Yes. As long as your resolution is 720p or above, and has a 16:9 ratio, it should - Basically, 1080p, 1440p, 4k and above should work without issues, albeit, the higher the resolution, the slower. @@ -131,6 +124,9 @@ Having translations for the instructions for other languages might be useful, bu - This might be because the PC version has a different name for the skill, add it to the corrections.lang.csv file, or tell me to do it. - An example of this would be `Quick Sheath`, which is named `Quick Sheathe` on PC - Make sure you give me both versions of the skill name if you think the PC version messed up again. +- Q: Can I record in windowed mode + - Yes. + - Yes, but if you have the "top bar" in your recording you will need the "Remove Black Bars" feature. You should try not recording the full window and only the game. # Notes - Version 1.5 is the last version that will officially support console mode, I may fix it from time to time if I need it for dev reasons, but I don't want to maintain a secondary workflow that will likely be used by nobody. diff --git a/data/translations/eng.json b/data/translations/eng.json index 76ddcc6..f8d412e 100644 --- a/data/translations/eng.json +++ b/data/translations/eng.json @@ -7,7 +7,7 @@ "input-dir": "Input video location: ", "frame-dir": "Frame location: ", "skipping-frames": "Skipping frame extraction: ", - "skip-frames": "Skips frames extraction\n (Recover from previous run)", + "skip-frames": "Skip frames extraction\n (Recover from previous run)", "skip-charms": "Skip charm extraction (Why??)", "delete-frames": "Delete old frames", "deleting-frames": "Deleting existing frames: ", @@ -68,5 +68,9 @@ "tess-wait-5-retry": "Waiting 5 seconds before trying to download the language pack again...", "tess-url-error": "A URL error occured, this might be a DNS issue... retrying", "tess-cannot-download": "Unable to download Tesseract language pack.", - "tess-not-found": "Tesseract was not found. Please install it, and if it is installed, pass it as a command line option at least once. If you have done both and it still isn't found, please open an issue on Github." + "tess-not-found": "Tesseract was not found. Please install it, and if it is installed, pass it as a command line option at least once. If you have done both and it still isn't found, please open an issue on Github.", + "remove-black-bars": "Remove black bars\nMay work with windowed capture", + "remove-black-bars-info": "The app will attempt to remove black bars.\nIt should work if you are recording in windowed mode.\nThis should be useful if your switch isn't properly scaled (TV Size setting).\nThis is 100% experimental (and somewhat random). Fix your videos before you complain :)", + "upd-ignore": "Ignore", + "add-as-is": "Add skill as-is" } \ No newline at end of file diff --git a/data/translations/fra.json b/data/translations/fra.json index 01ed334..1265ca9 100644 --- a/data/translations/fra.json +++ b/data/translations/fra.json @@ -7,7 +7,7 @@ "input-dir": "Dossier des vidéos: ", "frame-dir": "Dossier des frames: ", "skipping-frames": "Sauter l'extraction des frames: ", - "skip-frames": "Ignore l'extraction des frames\n (Récupération d'une exécution échouée)", + "skip-frames": "Sauter l'extraction des frames\n(Récupération d'une exécution échouée)", "skip-charms": "Sauter l'extraction des charmes (Pourquoi??)", "delete-frames": "Supprimer les anciens frames", "deleting-frames": "Suppression des frames: ", @@ -65,8 +65,12 @@ "wiki-button": "Visiter le MHR Set Searcher", "wiki-clipboard": "Copier l'URL", "wiki-attempt": "Tentative d'ouverture du site web...", - "tess-wait-5-retry":"Pause de 5 secondes avant de ré-essayer le téléchargement du language pack...", - "tess-url-error":"Une erreur d'URL s'est produite, potentiellement causé par une erreur DNS...", - "tess-cannot-download":"Impossible de télécharger le language pack Tesseract.", - "tess-not-found": "Tesseract n'a pas été trouv. Veuillez l'installer, s'il est installé, passez le à travers le command line au moins une fois. Si cette erreur continue d'apparaître, veuillez créer une issue sur Github.." + "tess-wait-5-retry": "Pause de 5 secondes avant de ré-essayer le téléchargement du language pack...", + "tess-url-error": "Une erreur d'URL s'est produite, potentiellement causé par une erreur DNS...", + "tess-cannot-download": "Impossible de télécharger le language pack Tesseract.", + "tess-not-found": "Tesseract n'a pas été trouv. Veuillez l'installer, s'il est installé, passez le à travers le command line au moins une fois. Si cette erreur continue d'apparaître, veuillez créer une issue sur Github..", + "remove-black-bars": "Retirer les barres noires\nDevrait marcher avec le mode fenêtre", + "remove-black-bars-info": "L'application va essayer d'enlever les barres noires autour du vidéo.\n¨Ça devrait aussi fonctionner si vous enregistrer le jeu en mode fenêtre.\nC'est utile lorsque vous n'avez pas configuré la taille de la TV pour la switch.\nC'est 100% expérimental et un peu aléatoire.\nEnregistrez les vidéos comme il faut avant de vous plaindre :)", + "upd-ignore": "Ignorer", + "add-as-is": "Ajouter tel quel" } \ No newline at end of file diff --git a/data/versions.json b/data/versions.json index 45b811d..b37a57d 100644 --- a/data/versions.json +++ b/data/versions.json @@ -1,10 +1,10 @@ { - "app": "1.6.2", + "app": "1.7", "skills": "3.1.1", "languages": { - "eng": "1.2", + "eng": "1.2.1", "jpn": 0, - "fra": "1.2", + "fra": "1.2.1", "ita": 0, "deu": 0, "spa": 0, diff --git a/images/slots/slot4.png b/images/slots/slot4.png new file mode 100644 index 0000000000000000000000000000000000000000..1dfccc41ace026a4dc5df4045a9b751a93e41156 GIT binary patch literal 2516 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 SimpleSemVer: + config = _load_config() + try: + return ( + SimpleSemVer(config["skipped-version"]) + if "skipped-version" in config + else None + ) + except: + save_ignored_update(None) + return None + + def get_tesseract_location(): config = _load_config() if "tesseract-directory" in config: @@ -296,6 +334,7 @@ def default_lang(): "slot1": _alter_resource_path(os.path.join("images", "slots", "slot1.png")), "slot2": _alter_resource_path(os.path.join("images", "slots", "slot2.png")), "slot3": _alter_resource_path(os.path.join("images", "slots", "slot3.png")), + "slot4": _alter_resource_path(os.path.join("images", "slots", "slot4.png")), "mask": _alter_resource_path(os.path.join("images", "mask.png")), "charm_only": _alter_resource_path(os.path.join("images", "charm_only.png")), "skill_mask": _alter_resource_path(os.path.join("images", "skill_mask.png")), diff --git a/src/tesseract/tesseract_utils.py b/src/tesseract/tesseract_utils.py index 44c5a51..b4b0469 100644 --- a/src/tesseract/tesseract_utils.py +++ b/src/tesseract/tesseract_utils.py @@ -143,7 +143,7 @@ def find_tesseract(silent=False): ) -def override_tessdata(): +def use_localappdata_tess(): base_path = HOME if WINDOWS: base_path = os.getenv("LOCALAPPDATA") or HOME @@ -154,17 +154,13 @@ def override_tessdata(): def set_tessdata(): if _is_pyinstaller(): - override_tessdata() + use_localappdata_tess() return if "TESSDATA_PREFIX" in os.environ: return - path = find_tesseract(silent=True) - path = os.path.dirname(path) - TESSDATA_PREFIX = os.path.join(path, "tessdata") - os.environ["TESSDATA_PREFIX"] = TESSDATA_PREFIX - logger.debug(f"Set 'TESSDATA_PREFIX' to {TESSDATA_PREFIX}") + use_localappdata_tess() def get_datapath(): @@ -172,7 +168,7 @@ def get_datapath(): set_tessdata() if os.environ["TESSDATA_PREFIX"] == "tessdata": - override_tessdata() + use_localappdata_tess() return os.environ["TESSDATA_PREFIX"] @@ -204,7 +200,7 @@ def download_language_data(lang="eng", _=lambda x: x, retry=False): except PermissionError as e: print(_("tess-permission-denied")) if not retry: - override_tessdata() + use_localappdata_tess() download_language_data(lang, _, retry=True) except URLError as e: print(_("tess-url-error")) diff --git a/src/ui/AskUpdate.py b/src/ui/AskUpdate.py index f92dc8e..ca4dc67 100644 --- a/src/ui/AskUpdate.py +++ b/src/ui/AskUpdate.py @@ -12,6 +12,12 @@ class UpdateType(Enum): SkillCorrections = 3 +class UpdateAction(Enum): + Nothing = 0 + Update = 1 + Ignore = 2 + + class AskUpdate(tk.Toplevel): def __init__( self, @@ -20,6 +26,7 @@ def __init__( update_type: UpdateType, local: SimpleSemVer, remote: SimpleSemVer, + show_ignore=False, ): super().__init__(parent) self._ = _ @@ -40,6 +47,9 @@ def __init__( self.lang_lbl.grid(row=0, columnspan=2) self.yes_btn.grid(row=1, column=0, sticky="e") self.no_btn.grid(row=1, column=1, sticky="w") + if show_ignore: + self.ignore_btn = tk.Button(self, text=_("upd-ignore"), command=self.ignore) + self.ignore_btn.grid(row=2, column=0, columnspan=2) def build_message(self, update_type, local, remote, _): return _( @@ -52,9 +62,13 @@ def build_message(self, update_type, local, remote, _): ).format(local, remote) def yes(self): - self.answer = True + self.answer = UpdateAction.Update self.destroy() def no(self): - self.answer = False + self.answer = UpdateAction.Nothing + self.destroy() + + def ignore(self): + self.answer = UpdateAction.Ignore self.destroy() diff --git a/src/ui/MainWindow.py b/src/ui/MainWindow.py index cc5d1f0..1d3ccd3 100644 --- a/src/ui/MainWindow.py +++ b/src/ui/MainWindow.py @@ -48,7 +48,9 @@ def __init__(self, _: Translator, args, skill_language_code, app_langs): self.input_dir = tk.StringVar(value=args.input_dir) self.frame_dir = tk.StringVar(value=args.frame_dir) - self.lang = tk.StringVar(value=get_language_from_code(skill_language_code)) + self.lang = tk.StringVar( + value=translate_lang(get_language_from_code(skill_language_code)) + ) self.app_lang = tk.StringVar(value=translate_lang(_.language)) self.charm_json = args.charm_json @@ -56,6 +58,7 @@ def __init__(self, _: Translator, args, skill_language_code, app_langs): self.skip_frames = tk.IntVar(value=args.skip_frames) self.skip_charms = tk.IntVar(value=args.skip_charms) + self.remove_black_bars = tk.IntVar(value=False) self.autosave = tk.IntVar(value=1) self.delete_frames_val = tk.IntVar() @@ -122,9 +125,18 @@ def _runtime_opts(parent=self): runtime_frame, text=_("skip-charms"), variable=self.skip_charms ) + self.remove_black_bars_box = tk.Checkbutton( + runtime_frame, + text=_("remove-black-bars"), + variable=self.remove_black_bars, + command=self._black_bar_activated, + ) + self.autosave_box.grid(column=1, row=1, sticky="w") self.del_frames_box.grid(column=1, row=2, sticky="w") self.skip_frames_box.grid(column=1, row=3, sticky="w") + self.remove_black_bars_box.grid(column=1, row=4, sticky="w") + # self.skip_charms_box.grid(column=0, row=4, sticky="w") # Hidden for now return runtime_frame @@ -311,6 +323,7 @@ def run(self, _: Translator = None): extract_unique_frames( self.input_dir.get(), self.frame_dir.get(), + self.remove_black_bars.get(), _, self.pbar, self.progress_callback, @@ -419,6 +432,12 @@ def _regen_paths(self): os.makedirs(self.input_dir.get(), exist_ok=True) os.makedirs(self.frame_dir.get(), exist_ok=True) + def _black_bar_activated(self, _=None): + if _ is None: + _ = self._ + if self.remove_black_bars.get(): + print(_("remove-black-bars-info")) + def write(self, *message, end="\n", sep=" "): text = "" for item in message: diff --git a/src/ui/ParseRepairWindow.py b/src/ui/ParseRepairWindow.py index 7314591..5541149 100644 --- a/src/ui/ParseRepairWindow.py +++ b/src/ui/ParseRepairWindow.py @@ -79,6 +79,11 @@ def _bottom_buttons(parent=self): btn_cancel.grid(row=2, column=0, sticky="w") btn_empty.grid(row=2, column=1, sticky="w") self.btn_ok.grid(row=2, column=2, sticky="w") + + self.btn_add_anyway = tk.Button( + frame, text=_("add-as-is"), command=self.select_as_is + ) + self.btn_add_anyway.grid(row=3, column=0, columnspan=3) return frame def _lbl(parent=self): @@ -119,9 +124,11 @@ def _lbl(parent=self): def check_valid_skill(self, *args): new_name = self.selected.get() if not is_skill(self.all_skills, new_name): + self.btn_add_anyway["state"] = "normal" self.btn_ok["state"] = "disabled" self.unbind("") else: + self.btn_add_anyway["state"] = "disabled" self.btn_ok["state"] = "normal" self.bind("", self.select_skill) @@ -140,13 +147,15 @@ def feed_charm(self, charm): def feed_error(self, error): self.current_error = error skill_img, parsed, level, error_type = error + if "chi" in self.language or self.language == "kor" or self.language == "jpn": + parsed = parsed.replace(" ", "") b, g, r = cv2.split(skill_img) im = Image.fromarray(cv2.merge((r, g, b))) imgtk = ImageTk.PhotoImage(image=im) self.img_value_lbl.configure(image=imgtk) self.img_value_lbl.image = imgtk self.parsed.set(parsed) - self.selected.set("") + self.selected.set(parsed) self.lvl.set(level) self.update() @@ -164,6 +173,9 @@ def select_empty(self): def select_skill(self, *args): self.select("skill") + def select_as_is(self, *args): + self.select("as-is") + def try_next_charm(self): try: self.feed_charm(next(self.charm_iter)) @@ -188,4 +200,7 @@ def select(self, action): self.fixed_skills[ fix_skill_name(self.all_skills, self.selected.get()) ] = self.current_error[2] + elif action == "as-is": + self.fixed_skills[self.selected.get()] = self.current_error[2] + self.try_next_error() diff --git a/src/updater/updater_utils.py b/src/updater/updater_utils.py index 70131ef..45f1760 100644 --- a/src/updater/updater_utils.py +++ b/src/updater/updater_utils.py @@ -1,50 +1,43 @@ +from ..resources import get_ignored_update, save_ignored_update from .VersionChecker import VersionChecker from .Updater import Updater -from ..ui.AskUpdate import AskUpdate, UpdateType +from ..ui.AskUpdate import UpdateAction, AskUpdate, UpdateType def ask_main_update(version_checker: VersionChecker, main_window, _): new_update, cur_ver, online_ver = version_checker.check_app_version() - answer = False + answer = UpdateAction.Nothing if new_update: - answer = _spawn_window(main_window, _, UpdateType.App, cur_ver, online_ver) - if answer: + skipped = get_ignored_update() + if skipped is not None and online_ver == skipped: + return answer + + answer = _spawn_window( + main_window, _, UpdateType.App, cur_ver, online_ver, True + ) + if answer == UpdateAction.Update: updater = Updater(_, version_checker) updater.update_main_app() + + elif answer == UpdateAction.Ignore: + save_ignored_update(online_ver) + return answer def ask_skill_update(version_checker: VersionChecker, main_window, _): new_update, cur_ver, online_ver = version_checker.check_skill_version() - answer = False + answer = UpdateAction.Nothing if new_update: answer = _spawn_window(main_window, _, UpdateType.Skills, cur_ver, online_ver) - if answer: + if answer == UpdateAction.Update: updater = Updater(_, version_checker) updater.update_all_skills(online_ver) return answer -def ask_language_update( - version_checker: VersionChecker, main_window, app_language_code, _ -): - new_update, cur_ver, online_ver = version_checker.check_language_version( - app_language_code - ) - - answer = False - if new_update: - answer = _spawn_window( - main_window, _, UpdateType.AppLanguage, cur_ver, online_ver - ) - if answer: - updater = Updater(_, version_checker) - updater.update_language(app_language_code, online_ver) - return answer - - def ask_corrections_update( version_checker: VersionChecker, main_window, skill_language_code, _ ): @@ -52,18 +45,18 @@ def ask_corrections_update( skill_language_code ) - answer = False + answer = UpdateAction.Nothing if new_update: answer = _spawn_window( main_window, _, UpdateType.SkillCorrections, cur_ver, online_ver ) - if answer: + if answer == UpdateAction.Update: updater = Updater(_, version_checker) updater.update_skill_corrections(skill_language_code, online_ver) return answer -def _spawn_window(main_window, _, update_type, cur_ver, online_ver): - askup = AskUpdate(main_window, _, update_type, cur_ver, online_ver) +def _spawn_window(main_window, _, update_type, cur_ver, online_ver, show_ignore=False): + askup = AskUpdate(main_window, _, update_type, cur_ver, online_ver, show_ignore) main_window.wait_window(askup) return askup.answer diff --git a/src/utils.py b/src/utils.py index 4ccda33..15376f2 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,10 +1,11 @@ import os import cv2 +from cv2 import norm import numpy as np from skimage.metrics import structural_similarity from math import floor from .tesseract.tesseract_utils import process_image_with_tesseract -from .resources import get_resource_path +from .resources import get_black_bar_threshold, get_resource_path def is_skill(skill_dict, skill_name): @@ -98,22 +99,23 @@ def get_slots(img): slot1 = cv2.imread(get_resource_path("slot1")) slot2 = cv2.imread(get_resource_path("slot2")) slot3 = cv2.imread(get_resource_path("slot3")) + slot4 = cv2.imread(get_resource_path("slot4")) spot1 = img[y : y + h, x1 : x1 + w] spot2 = img[y : y + h, x2 : x2 + w] spot3 = img[y : y + h, x3 : x3 + w] slots = [] - most_similar = None j = 1 for spot in [spot1, spot2, spot3]: - score0 = structural_similarity(spot, slot0, multichannel=True) - score1 = structural_similarity(spot, slot1, multichannel=True) - score2 = structural_similarity(spot, slot2, multichannel=True) - score3 = structural_similarity(spot, slot3, multichannel=True) + score0 = structural_similarity(spot, slot0, channel_axis=-1) + score1 = structural_similarity(spot, slot1, channel_axis=-1) + score2 = structural_similarity(spot, slot2, channel_axis=-1) + score3 = structural_similarity(spot, slot3, channel_axis=-1) + score4 = structural_similarity(spot, slot4, channel_axis=-1) j += 1 - scores = [score0, score1, score2, score3] + scores = [score0, score1, score2, score3, score4] best = max(scores) for i, s in enumerate(scores): if s == best: @@ -215,3 +217,10 @@ def batchify_lazy(lst, batch_size): batch.append(item) i += 1 yield batch + + +def compare_pixel(pixel1, pixel2, threshold=None): + if threshold is None: + threshold = get_black_bar_threshold() + distance = norm(pixel1, pixel2) + return distance <= threshold