From 02c8e475a620145a626057d0785207a675953e86 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Tue, 18 Jun 2024 19:10:33 +0800 Subject: [PATCH] Fix: Amount slider on light background --- tasks/item/slider.py | 3 ++- tasks/item/synthesize.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tasks/item/slider.py b/tasks/item/slider.py index 9d4e8b950..af3c47ffe 100644 --- a/tasks/item/slider.py +++ b/tasks/item/slider.py @@ -49,7 +49,7 @@ class Slider: total = area[2] - area[0] parameters = { - 'prominence': 15, + 'prominence': 10, 'wlen': wlen, 'width': 2, 'distance': wlen / 2, @@ -58,6 +58,7 @@ class Slider: peaks, _ = signal.find_peaks(image, **parameters) peaks //= wlen diff = np.diff(peaks) + # print(diff) # Mask controller # Controller has orange border (240, 150, 57) and white center diff --git a/tasks/item/synthesize.py b/tasks/item/synthesize.py index d1683e8b5..c85cfcb64 100644 --- a/tasks/item/synthesize.py +++ b/tasks/item/synthesize.py @@ -37,7 +37,7 @@ def image_color_count(image, color, threshold=221): class WhiteStrip(Ocr): def pre_process(self, image): mask = color_similarity_2d(image, color=(255, 255, 255)) - mask = cv2.inRange(mask, 180, 255, dst=mask) + mask = cv2.inRange(mask, 160, 255, dst=mask) mask = np.mean(mask, axis=0) point = np.array(cv2.findNonZero(mask))[:, 0, 1] @@ -52,6 +52,13 @@ class SynthesizeItemName(OcrItemName, WhiteStrip): pass +class SynthesizeItemAmount(Digit, WhiteStrip): + def pre_process(self, image): + image = super().pre_process(image) + image = cv2.subtract((255, 255, 255, 0), image) + return image + + class SynthesizeInventoryManager(InventoryManager): @cached_property def dic_item_index(self): @@ -359,7 +366,7 @@ class Synthesize(CombatObtain, ItemUI): logger.hr('Synthesize amount set', level=2) slider = Slider(main=self, slider=SYNTHESIZE_SLIDER) slider.set(value, total) - ocr = Digit(SYNTHESIZE_AMOUNT, lang=server.lang) + ocr = SynthesizeItemAmount(SYNTHESIZE_AMOUNT, lang=server.lang) self.ui_ensure_index( value, letter=ocr, next_button=SYNTHESIZE_PLUS, prev_button=SYNTHESIZE_MINUS, interval=(0.1, 0.2))