|
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_x = 3 |
| 26 | + area = (self.area[0] - delta_x, self.area[1], self.area[2] + delta_x, self.area[3]) |
28 | 27 | 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 |
41 | 44 | mask = np.zeros((self.total,), dtype=np.bool_) |
42 | | - mask[peaks] = 1 |
| 45 | + mask[up:down] = True |
43 | 46 | return mask |
44 | 47 |
|
45 | 48 |
|
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), |
49 | 52 | name="EVENT_SHOP_SCROLL" |
50 | 53 | ) |
51 | 54 |
|
|
0 commit comments