Skip to content

Commit 16485ab

Browse files
committed
Fix: EVENT_SHOP_SCROLL.match_color()
1 parent afb2c08 commit 16485ab

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

module/shop_event/ui.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import cv2
21
import numpy as np
32
import re
43
from datetime import datetime, timedelta
5-
from scipy import signal
64

75
import module.config.server as server
86
from module.base.button import ButtonGrid
@@ -18,34 +16,39 @@
1816
from module.shop.assets import SHOP_OCR_BALANCE, SHOP_OCR_OIL_CHECK, SHOP_OCR_OIL
1917
from module.shop_event.assets import *
2018
from module.ui.navbar import Navbar
21-
from module.ui.scroll import AdaptiveScroll
19+
from module.ui.scroll import Scroll
2220
from module.ui.ui import UI
2321

2422

25-
class EventShopAdaptiveScroll(AdaptiveScroll):
23+
class EventShopScroll(Scroll):
2624
def match_color(self, main):
27-
area = (self.area[0] - self.background, self.area[1], self.area[2] + self.background, self.area[3])
25+
delta_x = 3
26+
area = (self.area[0] - delta_x, self.area[1], self.area[2] + delta_x, self.area[3])
2827
image = main.image_crop(area, copy=False)
29-
image = rgb2luma(image)
30-
cv2.bitwise_not(image, dst=image)
31-
image = image.flatten()
32-
width = area[2] - area[0]
33-
parameters = {
34-
'prominence': 60,
35-
'wlen': 2 * width + 1,
36-
}
37-
parameters.update(self.parameters)
38-
peaks, _ = signal.find_peaks(image, **parameters)
39-
peaks //= width
40-
self.length = len(peaks)
28+
image = rgb2luma(image).astype(np.float)
29+
dif = image[:, image.shape[1] // 2] / (image[:, 0] + image[:, -1])
30+
delta = np.diff(dif)
31+
peak_candidates = np.where(np.abs(delta) > 0.025)[0]
32+
if len(peak_candidates) == 2:
33+
assert delta[peak_candidates[0]] < 0 < delta[peak_candidates[1]]
34+
up, down = peak_candidates[0], peak_candidates[1]
35+
elif len(peak_candidates) == 1:
36+
if delta[peak_candidates[0]] > 0:
37+
up, down = 0, peak_candidates[0]
38+
else:
39+
up, down = peak_candidates[0], self.total
40+
else:
41+
logger.warning(f'peak_candidates: {peak_candidates}'
42+
f'peak_values: {delta[peak_candidates]}')
43+
up, down = 0, 100
4144
mask = np.zeros((self.total,), dtype=np.bool_)
42-
mask[peaks] = 1
45+
mask[up:down] = True
4346
return mask
4447

4548

46-
EVENT_SHOP_SCROLL = EventShopAdaptiveScroll(
47-
EVENT_SHOP_SCROLL_AREA.button,
48-
background=2,
49+
EVENT_SHOP_SCROLL = EventShopScroll(
50+
EVENT_SHOP_SCROLL_AREA,
51+
color=(0, 0, 0),
4952
name="EVENT_SHOP_SCROLL"
5053
)
5154

0 commit comments

Comments
 (0)