Skip to content

Commit 8a330ef

Browse files
committed
Fix: EVENT_SHOP_SCROLL.match_color()
1 parent afb2c08 commit 8a330ef

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

module/shop_event/ui.py

Lines changed: 28 additions & 20 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,44 @@
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_y = 5
26+
delta_x = 3
27+
area = (self.area[0] - delta_x, self.area[1] - delta_y, self.area[2] + delta_x, self.area[3] + delta_y)
2828
image = main.image_crop(area, copy=False)
2929
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)
30+
dif = image[:, 0].astype(np.int) + image[:, -1]- image[:, image.shape[1] // 2] - image[:, image.shape[1] // 2]
31+
dif = dif.flatten()
32+
delta = np.diff(dif)
33+
up_candidates = np.where(delta < -15)[0]
34+
down_candidates = np.where(delta > 15)[0]
35+
up_candidates -= delta_y - 1
36+
down_candidates -= delta_y - 1
37+
pairs = []
38+
for down in down_candidates:
39+
# only consider up spikes that occur AFTER the down spike
40+
ups = up_candidates[up_candidates > down]
41+
if len(ups) == 0:
42+
continue
43+
dists = ups - down
44+
for up, dist in zip(ups, dists):
45+
pairs.append((dist, down, up))
46+
47+
nearest = min(pairs, key=lambda x: x[0])
48+
_, nearest_down, nearest_up = nearest
4149
mask = np.zeros((self.total,), dtype=np.bool_)
42-
mask[peaks] = 1
50+
mask[nearest_down:nearest_up] = True
4351
return mask
4452

4553

46-
EVENT_SHOP_SCROLL = EventShopAdaptiveScroll(
47-
EVENT_SHOP_SCROLL_AREA.button,
48-
background=2,
54+
EVENT_SHOP_SCROLL = EventShopScroll(
55+
EVENT_SHOP_SCROLL_AREA,
56+
color=(0, 0, 0),
4957
name="EVENT_SHOP_SCROLL"
5058
)
5159

0 commit comments

Comments
 (0)