|
1 | | -import cv2 |
2 | 1 | import numpy as np |
3 | 2 | import re |
4 | 3 | from datetime import datetime, timedelta |
5 | | -from scipy import signal |
6 | 4 |
|
7 | 5 | import module.config.server as server |
8 | 6 | from module.base.button import ButtonGrid |
|
18 | 16 | from module.shop.assets import SHOP_OCR_BALANCE, SHOP_OCR_OIL_CHECK, SHOP_OCR_OIL |
19 | 17 | from module.shop_event.assets import * |
20 | 18 | from module.ui.navbar import Navbar |
21 | | -from module.ui.scroll import AdaptiveScroll |
| 19 | +from module.ui.scroll import Scroll |
22 | 20 | from module.ui.ui import UI |
23 | 21 |
|
24 | 22 |
|
25 | | -class EventShopAdaptiveScroll(AdaptiveScroll): |
| 23 | +class EventShopScroll(Scroll): |
26 | 24 | 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) |
28 | 28 | image = main.image_crop(area, copy=False) |
29 | 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) |
| 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 |
41 | 49 | mask = np.zeros((self.total,), dtype=np.bool_) |
42 | | - mask[peaks] = 1 |
| 50 | + mask[nearest_down:nearest_up] = True |
43 | 51 | return mask |
44 | 52 |
|
45 | 53 |
|
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), |
49 | 57 | name="EVENT_SHOP_SCROLL" |
50 | 58 | ) |
51 | 59 |
|
|
0 commit comments