kotonebot 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kotonebot/__init__.py +39 -39
- kotonebot/backend/bot.py +312 -312
- kotonebot/backend/color.py +525 -525
- kotonebot/backend/context/__init__.py +3 -3
- kotonebot/backend/context/task_action.py +183 -183
- kotonebot/backend/core.py +129 -129
- kotonebot/backend/debug/entry.py +89 -89
- kotonebot/backend/debug/mock.py +78 -78
- kotonebot/backend/debug/server.py +222 -222
- kotonebot/backend/debug/vars.py +351 -351
- kotonebot/backend/dispatch.py +227 -227
- kotonebot/backend/flow_controller.py +196 -196
- kotonebot/backend/ocr.py +535 -529
- kotonebot/backend/preprocessor.py +103 -103
- kotonebot/client/__init__.py +9 -9
- kotonebot/client/device.py +528 -503
- kotonebot/client/fast_screenshot.py +377 -377
- kotonebot/client/host/__init__.py +43 -12
- kotonebot/client/host/adb_common.py +107 -103
- kotonebot/client/host/custom.py +118 -114
- kotonebot/client/host/leidian_host.py +196 -201
- kotonebot/client/host/mumu12_host.py +353 -358
- kotonebot/client/host/protocol.py +214 -213
- kotonebot/client/host/windows_common.py +58 -58
- kotonebot/client/implements/__init__.py +71 -15
- kotonebot/client/implements/adb.py +89 -85
- kotonebot/client/implements/adb_raw.py +162 -158
- kotonebot/client/implements/nemu_ipc/__init__.py +11 -7
- kotonebot/client/implements/nemu_ipc/external_renderer_ipc.py +284 -284
- kotonebot/client/implements/nemu_ipc/nemu_ipc.py +327 -327
- kotonebot/client/implements/remote_windows.py +188 -188
- kotonebot/client/implements/uiautomator2.py +85 -81
- kotonebot/client/implements/windows.py +176 -172
- kotonebot/client/protocol.py +69 -69
- kotonebot/client/registration.py +24 -24
- kotonebot/config/base_config.py +96 -96
- kotonebot/config/manager.py +36 -36
- kotonebot/errors.py +76 -71
- kotonebot/interop/win/__init__.py +10 -3
- kotonebot/interop/win/_mouse.py +311 -0
- kotonebot/interop/win/message_box.py +313 -313
- kotonebot/interop/win/reg.py +37 -37
- kotonebot/interop/win/shortcut.py +43 -43
- kotonebot/interop/win/task_dialog.py +513 -513
- kotonebot/logging/__init__.py +2 -2
- kotonebot/logging/log.py +17 -17
- kotonebot/primitives/__init__.py +17 -17
- kotonebot/primitives/geometry.py +862 -290
- kotonebot/primitives/visual.py +63 -63
- kotonebot/tools/mirror.py +354 -354
- kotonebot/ui/file_host/sensio.py +36 -36
- kotonebot/ui/file_host/tmp_send.py +54 -54
- kotonebot/ui/pushkit/__init__.py +3 -3
- kotonebot/ui/pushkit/image_host.py +88 -87
- kotonebot/ui/pushkit/protocol.py +13 -13
- kotonebot/ui/pushkit/wxpusher.py +54 -53
- kotonebot/ui/user.py +148 -148
- kotonebot/util.py +436 -436
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/METADATA +82 -81
- kotonebot-0.5.0.dist-info/RECORD +71 -0
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/licenses/LICENSE +673 -673
- kotonebot-0.4.0.dist-info/RECORD +0 -70
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/WHEEL +0 -0
- {kotonebot-0.4.0.dist-info → kotonebot-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
from typing import Protocol, Literal
|
|
2
|
-
|
|
3
|
-
import cv2
|
|
4
|
-
import numpy as np
|
|
5
|
-
from cv2.typing import MatLike
|
|
6
|
-
|
|
7
|
-
ImageFormat = Literal['bgr', 'hsv']
|
|
8
|
-
|
|
9
|
-
class PreprocessorProtocol(Protocol):
|
|
10
|
-
"""预处理协议。用于 Image 与 Ocr 中的 `preprocessor` 参数。"""
|
|
11
|
-
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
12
|
-
"""
|
|
13
|
-
预处理图像。
|
|
14
|
-
|
|
15
|
-
:param image: 输入图像。
|
|
16
|
-
:param format: 输入图像的格式,可选值为 'bgr' 或 'hsv'。
|
|
17
|
-
:return: 预处理后的图像,格式不限。
|
|
18
|
-
"""
|
|
19
|
-
...
|
|
20
|
-
|
|
21
|
-
class HsvColorFilter(PreprocessorProtocol):
|
|
22
|
-
"""HSV 颜色过滤器。用于保留指定颜色。"""
|
|
23
|
-
def __init__(
|
|
24
|
-
self,
|
|
25
|
-
lower: tuple[int, int, int],
|
|
26
|
-
upper: tuple[int, int, int],
|
|
27
|
-
*,
|
|
28
|
-
name: str | None = None,
|
|
29
|
-
):
|
|
30
|
-
self.lower = np.array(lower)
|
|
31
|
-
self.upper = np.array(upper)
|
|
32
|
-
self.name = name
|
|
33
|
-
|
|
34
|
-
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
35
|
-
if format == 'bgr':
|
|
36
|
-
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
37
|
-
elif format == 'hsv':
|
|
38
|
-
hsv = image
|
|
39
|
-
else:
|
|
40
|
-
raise ValueError(f'Invalid format: {format}')
|
|
41
|
-
mask = cv2.inRange(hsv, self.lower, self.upper)
|
|
42
|
-
return mask
|
|
43
|
-
|
|
44
|
-
def __repr__(self) -> str:
|
|
45
|
-
return f'HsvColorFilter(for color "{self.name}" with range {self.lower} - {self.upper})'
|
|
46
|
-
|
|
47
|
-
class HsvColorRemover(PreprocessorProtocol):
|
|
48
|
-
"""去除指定范围内的 HSV 颜色。"""
|
|
49
|
-
|
|
50
|
-
def __init__(
|
|
51
|
-
self,
|
|
52
|
-
lower: tuple[int, int, int],
|
|
53
|
-
upper: tuple[int, int, int],
|
|
54
|
-
*,
|
|
55
|
-
name: str | None = None,
|
|
56
|
-
):
|
|
57
|
-
self.lower = np.array(lower)
|
|
58
|
-
self.upper = np.array(upper)
|
|
59
|
-
self.name = name
|
|
60
|
-
|
|
61
|
-
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
62
|
-
if format == 'bgr':
|
|
63
|
-
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
64
|
-
elif format == 'hsv':
|
|
65
|
-
hsv = image
|
|
66
|
-
else:
|
|
67
|
-
raise ValueError(f'Invalid format: {format}')
|
|
68
|
-
mask = cv2.inRange(hsv, self.lower, self.upper)
|
|
69
|
-
mask = cv2.bitwise_not(mask)
|
|
70
|
-
result = cv2.bitwise_and(image, image, mask=mask)
|
|
71
|
-
return result
|
|
72
|
-
|
|
73
|
-
def __repr__(self) -> str:
|
|
74
|
-
return f'HsvColorRemover(for color "{self.name}" with range {self.lower} - {self.upper})'
|
|
75
|
-
|
|
76
|
-
class HsvColorsRemover(PreprocessorProtocol):
|
|
77
|
-
"""去除多个指定范围内的 HSV 颜色。"""
|
|
78
|
-
def __init__(
|
|
79
|
-
self,
|
|
80
|
-
colors: list[tuple[tuple[int, int, int], tuple[int, int, int]]],
|
|
81
|
-
*,
|
|
82
|
-
name: str | None = None,
|
|
83
|
-
):
|
|
84
|
-
self.colors = colors
|
|
85
|
-
self.name = name
|
|
86
|
-
self.__preprocessors = [
|
|
87
|
-
HsvColorRemover(color[0], color[1], name=name) for color in colors
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
91
|
-
if format == 'bgr':
|
|
92
|
-
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
93
|
-
elif format == 'hsv':
|
|
94
|
-
hsv = image
|
|
95
|
-
else:
|
|
96
|
-
raise ValueError(f'Invalid format: {format}')
|
|
97
|
-
|
|
98
|
-
for p in self.__preprocessors:
|
|
99
|
-
hsv = p.process(hsv, format='hsv')
|
|
100
|
-
return hsv
|
|
101
|
-
|
|
102
|
-
def __repr__(self) -> str:
|
|
103
|
-
return f'HsvColorsRemover(for colors {self.colors})'
|
|
1
|
+
from typing import Protocol, Literal
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
from cv2.typing import MatLike
|
|
6
|
+
|
|
7
|
+
ImageFormat = Literal['bgr', 'hsv']
|
|
8
|
+
|
|
9
|
+
class PreprocessorProtocol(Protocol):
|
|
10
|
+
"""预处理协议。用于 Image 与 Ocr 中的 `preprocessor` 参数。"""
|
|
11
|
+
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
12
|
+
"""
|
|
13
|
+
预处理图像。
|
|
14
|
+
|
|
15
|
+
:param image: 输入图像。
|
|
16
|
+
:param format: 输入图像的格式,可选值为 'bgr' 或 'hsv'。
|
|
17
|
+
:return: 预处理后的图像,格式不限。
|
|
18
|
+
"""
|
|
19
|
+
...
|
|
20
|
+
|
|
21
|
+
class HsvColorFilter(PreprocessorProtocol):
|
|
22
|
+
"""HSV 颜色过滤器。用于保留指定颜色。"""
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
lower: tuple[int, int, int],
|
|
26
|
+
upper: tuple[int, int, int],
|
|
27
|
+
*,
|
|
28
|
+
name: str | None = None,
|
|
29
|
+
):
|
|
30
|
+
self.lower = np.array(lower)
|
|
31
|
+
self.upper = np.array(upper)
|
|
32
|
+
self.name = name
|
|
33
|
+
|
|
34
|
+
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
35
|
+
if format == 'bgr':
|
|
36
|
+
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
37
|
+
elif format == 'hsv':
|
|
38
|
+
hsv = image
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(f'Invalid format: {format}')
|
|
41
|
+
mask = cv2.inRange(hsv, self.lower, self.upper)
|
|
42
|
+
return mask
|
|
43
|
+
|
|
44
|
+
def __repr__(self) -> str:
|
|
45
|
+
return f'HsvColorFilter(for color "{self.name}" with range {self.lower} - {self.upper})'
|
|
46
|
+
|
|
47
|
+
class HsvColorRemover(PreprocessorProtocol):
|
|
48
|
+
"""去除指定范围内的 HSV 颜色。"""
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
lower: tuple[int, int, int],
|
|
53
|
+
upper: tuple[int, int, int],
|
|
54
|
+
*,
|
|
55
|
+
name: str | None = None,
|
|
56
|
+
):
|
|
57
|
+
self.lower = np.array(lower)
|
|
58
|
+
self.upper = np.array(upper)
|
|
59
|
+
self.name = name
|
|
60
|
+
|
|
61
|
+
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
62
|
+
if format == 'bgr':
|
|
63
|
+
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
64
|
+
elif format == 'hsv':
|
|
65
|
+
hsv = image
|
|
66
|
+
else:
|
|
67
|
+
raise ValueError(f'Invalid format: {format}')
|
|
68
|
+
mask = cv2.inRange(hsv, self.lower, self.upper)
|
|
69
|
+
mask = cv2.bitwise_not(mask)
|
|
70
|
+
result = cv2.bitwise_and(image, image, mask=mask)
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
def __repr__(self) -> str:
|
|
74
|
+
return f'HsvColorRemover(for color "{self.name}" with range {self.lower} - {self.upper})'
|
|
75
|
+
|
|
76
|
+
class HsvColorsRemover(PreprocessorProtocol):
|
|
77
|
+
"""去除多个指定范围内的 HSV 颜色。"""
|
|
78
|
+
def __init__(
|
|
79
|
+
self,
|
|
80
|
+
colors: list[tuple[tuple[int, int, int], tuple[int, int, int]]],
|
|
81
|
+
*,
|
|
82
|
+
name: str | None = None,
|
|
83
|
+
):
|
|
84
|
+
self.colors = colors
|
|
85
|
+
self.name = name
|
|
86
|
+
self.__preprocessors = [
|
|
87
|
+
HsvColorRemover(color[0], color[1], name=name) for color in colors
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
def process(self, image: MatLike, *, format: ImageFormat = 'bgr') -> MatLike:
|
|
91
|
+
if format == 'bgr':
|
|
92
|
+
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
93
|
+
elif format == 'hsv':
|
|
94
|
+
hsv = image
|
|
95
|
+
else:
|
|
96
|
+
raise ValueError(f'Invalid format: {format}')
|
|
97
|
+
|
|
98
|
+
for p in self.__preprocessors:
|
|
99
|
+
hsv = p.process(hsv, format='hsv')
|
|
100
|
+
return hsv
|
|
101
|
+
|
|
102
|
+
def __repr__(self) -> str:
|
|
103
|
+
return f'HsvColorsRemover(for colors {self.colors})'
|
kotonebot/client/__init__.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
from .device import Device
|
|
2
|
-
from .registration import DeviceImpl
|
|
3
|
-
|
|
4
|
-
# 确保所有实现都被注册
|
|
5
|
-
from . import implements # noqa: F401
|
|
6
|
-
|
|
7
|
-
__all__ = [
|
|
8
|
-
'Device',
|
|
9
|
-
'DeviceImpl',
|
|
1
|
+
from .device import Device
|
|
2
|
+
from .registration import DeviceImpl
|
|
3
|
+
|
|
4
|
+
# 确保所有实现都被注册
|
|
5
|
+
from . import implements # noqa: F401
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'Device',
|
|
9
|
+
'DeviceImpl',
|
|
10
10
|
]
|