ascript 1.3.27__py3-none-win_amd64.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.
- ascript/__init__.py +8 -0
- ascript/hooks/__init__.py +0 -0
- ascript/hooks/hook-ascript.py +2 -0
- ascript/windows/__init__.py +29 -0
- ascript/windows/daos/__init__.py +0 -0
- ascript/windows/daos/screen.py +143 -0
- ascript/windows/hardware/__init__.py +5 -0
- ascript/windows/hardware/keyboard.py +279 -0
- ascript/windows/hardware/logitech_driver.py +179 -0
- ascript/windows/hardware/mouse.py +308 -0
- ascript/windows/license/__init__.py +16 -0
- ascript/windows/license/achttp.cp310-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp311-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp312-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp313-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp314-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp38-win_amd64.pyd +0 -0
- ascript/windows/license/achttp.cp39-win_amd64.pyd +0 -0
- ascript/windows/media/__init__.py +0 -0
- ascript/windows/resources/__init__.py +0 -0
- ascript/windows/resources/libs/logitech/x64/LogitechGkeyEnginesWrapper.dll +0 -0
- ascript/windows/resources/libs/logitech/x86/LogitechGkeyEnginesWrapper.dll +0 -0
- ascript/windows/resources/templates/__init__.py +0 -0
- ascript/windows/resources/templates/__init__py.win.template +51 -0
- ascript/windows/resources/templates/build.as.win.template +14 -0
- ascript/windows/resources/templates/build.py +71 -0
- ascript/windows/resources/templates/logo_windows.ico +0 -0
- ascript/windows/resources/templates/windows/main.py +50 -0
- ascript/windows/resources/templates/windows/pyproject.toml +44 -0
- ascript/windows/resources/templates/windows/res/img/logo.ico +0 -0
- ascript/windows/screen/__init__.py +13 -0
- ascript/windows/screen/as_cv.py +382 -0
- ascript/windows/screen/canny.py +128 -0
- ascript/windows/screen/code_scanner.py +72 -0
- ascript/windows/screen/color_algorithms.py +277 -0
- ascript/windows/screen/find_colors.py +251 -0
- ascript/windows/screen/find_images.py +217 -0
- ascript/windows/screen/ocr/__init__.py +4 -0
- ascript/windows/screen/ocr/ocr.py +223 -0
- ascript/windows/screen/ocr/rapidocr_hook.py +301 -0
- ascript/windows/screen/ocrx.py +169 -0
- ascript/windows/screen/screen_core.py +139 -0
- ascript/windows/store/__init__.py +21 -0
- ascript/windows/system/__init__.py +8 -0
- ascript/windows/system/device.py +355 -0
- ascript/windows/system/easy_print.py +115 -0
- ascript/windows/system/env.py +492 -0
- ascript/windows/system/exception/__init__.py +1 -0
- ascript/windows/system/key_value.py +145 -0
- ascript/windows/system/pip.py +175 -0
- ascript/windows/system/r.py +165 -0
- ascript/windows/system/runtime.py +62 -0
- ascript/windows/tools/__init__.py +27 -0
- ascript/windows/tools/__main__.py +21 -0
- ascript/windows/tools/action.json +33 -0
- ascript/windows/tools/action.py +168 -0
- ascript/windows/tools/colors_tool.py +391 -0
- ascript/windows/tools/config.py +26 -0
- ascript/windows/tools/dumptool.py +18 -0
- ascript/windows/tools/eel_api.py +495 -0
- ascript/windows/tools/gpplug/__init__.py +0 -0
- ascript/windows/tools/gpplug/plug.py +70 -0
- ascript/windows/tools/mouse_catch.py +168 -0
- ascript/windows/tools/plug_manager.py +38 -0
- ascript/windows/tools/tool_api.py +906 -0
- ascript/windows/tools/tool_window.py +56 -0
- ascript/windows/tools/uia_worker.py +365 -0
- ascript/windows/tools/web/app_store_window.html +481 -0
- ascript/windows/tools/web/colors.html +532 -0
- ascript/windows/tools/web/css/screen.css +1342 -0
- ascript/windows/tools/web/css/viewtree.css +357 -0
- ascript/windows/tools/web/flot_control.html +195 -0
- ascript/windows/tools/web/img/ico/favicon.png +0 -0
- ascript/windows/tools/web/img/ico/paintpalette.png +0 -0
- ascript/windows/tools/web/img/svg/find_colors.svg +1 -0
- ascript/windows/tools/web/img/svg/find_images.svg +1 -0
- ascript/windows/tools/web/img/svg/illustration-6.svg +89 -0
- ascript/windows/tools/web/img/svg/img_default.svg +1 -0
- ascript/windows/tools/web/img/svg/ocr.svg +1 -0
- ascript/windows/tools/web/js/screen/colors.js +466 -0
- ascript/windows/tools/web/js/screen/gp_plug.js +108 -0
- ascript/windows/tools/web/js/screen/image_mouse.js +464 -0
- ascript/windows/tools/web/js/screen/img_view.js +558 -0
- ascript/windows/tools/web/js/screen/plug.js +246 -0
- ascript/windows/tools/web/js/screen/screen.js +690 -0
- ascript/windows/tools/web/js/screen/screen_api.js +778 -0
- ascript/windows/tools/web/js/screen/screen_maker.js +10 -0
- ascript/windows/tools/web/js/utils/map.js +73 -0
- ascript/windows/tools/web/js/utils/upload.js +157 -0
- ascript/windows/tools/web/js/viewtree/niv_js.js +27 -0
- ascript/windows/tools/web/js/viewtree/vtree.js +1510 -0
- ascript/windows/tools/web/libs/bootstrap/css/bootstrap.min.css +6 -0
- ascript/windows/tools/web/libs/bootstrap/js/bootstrap.bundle.min.js +7 -0
- ascript/windows/tools/web/libs/bootstrap-icons/0-circle.svg +4 -0
- ascript/windows/tools/web/libs/bootstrap-icons/0-square.svg +4 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/bootstrap-icons.css +2078 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/bootstrap-icons.json +2052 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/bootstrap-icons.min.css +5 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/bootstrap-icons.scss +2090 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/fonts/bootstrap-icons.woff +0 -0
- ascript/windows/tools/web/libs/bootstrap-icons/font/fonts/bootstrap-icons.woff2 +0 -0
- ascript/windows/tools/web/libs/feather-icons/dist/feather.min.js +13 -0
- ascript/windows/tools/web/libs/feather-icons/dist/icons.json +1 -0
- ascript/windows/tools/web/libs/jquery/core.js +399 -0
- ascript/windows/tools/web/libs/jquery/jquery.js +10598 -0
- ascript/windows/tools/web/libs/jquery/jquery.min.js +4 -0
- ascript/windows/tools/web/libs/jquery/jquery.min.js.zip +0 -0
- ascript/windows/tools/web/libs/jquery/jquery.slim.js +8495 -0
- ascript/windows/tools/web/libs/jquery/jquery.slim.min.js +2 -0
- ascript/windows/tools/web/libs/jquery-menu/jquery.contextMenu.js +2134 -0
- ascript/windows/tools/web/libs/jquery-menu/jquery.contextMenu.min.css +16 -0
- ascript/windows/tools/web/libs/jquery-zTree/css/zTreeStyle.css +97 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/1_close.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/1_open.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/2.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/3.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/4.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/5.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/6.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/7.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/8.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/diy/9.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/line_conn.gif +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/loading.gif +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/tree-node-btn.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/zTreeStandard.gif +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/img/zTreeStandard.png +0 -0
- ascript/windows/tools/web/libs/jquery-zTree/js/jquery.ztree.all.min.js +3 -0
- ascript/windows/tools/web/libs/treeview/css/jquery.treeview.css +79 -0
- ascript/windows/tools/web/libs/treeview/img/file.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/ico_loading.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/icon4.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/icon5.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/icon6.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/py.png +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-black-line.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-black.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-default-line.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-default.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-famfamfam-line.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-famfamfam.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-gray-line.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-gray.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-red-line.gif +0 -0
- ascript/windows/tools/web/libs/treeview/img/treeview-red.gif +0 -0
- ascript/windows/tools/web/libs/treeview/js/jquery.treeview.edit.js +37 -0
- ascript/windows/tools/web/libs/treeview/js/jquery.treeview.js +250 -0
- ascript/windows/tools/web/license_window.html +255 -0
- ascript/windows/tools/web/plugs/a.html +653 -0
- ascript/windows/tools/web/plugs/demo.html +52 -0
- ascript/windows/tools/web/plugs/find_colors.html +629 -0
- ascript/windows/tools/web/plugs/find_images.html +699 -0
- ascript/windows/tools/web/plugs/rapidocr.html +954 -0
- ascript/windows/tools/web/vtree.html +496 -0
- ascript/windows/tools/webview/assets/index-HymBPl-I.css +1 -0
- ascript/windows/tools/webview/assets/index-PqA_m8tL.js +17 -0
- ascript/windows/tools/webview/index.html +13 -0
- ascript/windows/ui/__init__.py +6 -0
- ascript/windows/ui/app_store_window.py +272 -0
- ascript/windows/ui/draw_window.py +231 -0
- ascript/windows/ui/flot_test.py +297 -0
- ascript/windows/ui/flot_window.py +488 -0
- ascript/windows/ui/license_window.py +111 -0
- ascript/windows/ui/web_window.py +466 -0
- ascript/windows/utils/__init__.py +0 -0
- ascript/windows/utils/node_utils.py +20 -0
- ascript/windows/utils/screen_utils.py +280 -0
- ascript/windows/window/Selector.py +1015 -0
- ascript/windows/window/Window.py +747 -0
- ascript/windows/window/__init__.py +5 -0
- ascript/windows/window/launcher.py +213 -0
- ascript/windows/window/uia_runtime.py +26 -0
- ascript-1.3.27.dist-info/METADATA +41 -0
- ascript-1.3.27.dist-info/RECORD +177 -0
- ascript-1.3.27.dist-info/WHEEL +5 -0
- ascript-1.3.27.dist-info/entry_points.txt +2 -0
- ascript-1.3.27.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""屏幕颜色查找工具模块。
|
|
2
|
+
|
|
3
|
+
提供基于像素颜色的多点查找、颜色比较等屏幕图像分析功能。
|
|
4
|
+
支持多种扫描方向和相似度容差匹配。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from PIL.Image import Image
|
|
8
|
+
|
|
9
|
+
from ascript.windows.daos.screen import Point, Color
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def find_colors(colors: str, sim: float, max_points: int, ore: int, img: Image, space: int) -> list:
|
|
13
|
+
"""在图像中查找多点颜色匹配的位置。
|
|
14
|
+
|
|
15
|
+
根据给定的多点颜色描述字符串,在图像中搜索匹配的位置。
|
|
16
|
+
第一个点作为基准点,后续点的坐标相对于基准点计算偏移量。
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
colors: 多点颜色描述字符串,格式为 'x1,y1,#RRGGBB|x2,y2,#RRGGBB|...',
|
|
20
|
+
多个点之间用 '|' 分隔,每个点包含坐标和十六进制颜色值。
|
|
21
|
+
sim: 颜色相似度,取值范围 0.0 到 1.0,1.0 表示完全匹配。
|
|
22
|
+
max_points: 最大返回匹配点数,-1 表示不限制。
|
|
23
|
+
ore: 扫描方向,取值 1-8,对应不同的扫描顺序。
|
|
24
|
+
img: 待搜索的 PIL 图像对象。
|
|
25
|
+
space: 找到匹配后的排除间距,避免重复匹配相邻区域。
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
list: 匹配到的 Point 坐标点列表。
|
|
29
|
+
"""
|
|
30
|
+
sim_space = 255 * (1 - sim)
|
|
31
|
+
cs = colors.split('|')
|
|
32
|
+
points = [None] * len(cs)
|
|
33
|
+
for i in range(len(cs)):
|
|
34
|
+
c = cs[i].split(',')
|
|
35
|
+
if i == 0:
|
|
36
|
+
points[i] = {'x': int(c[0]), 'y': int(c[1]), 'color': Color(c[2]).to_rgb()}
|
|
37
|
+
else:
|
|
38
|
+
points[i] = {'x': int(c[0]) - points[0]['x'], 'y': int(c[1]) - points[0]['y'],
|
|
39
|
+
'color': Color(c[2]).to_rgb()}
|
|
40
|
+
|
|
41
|
+
return native_find_colors(sim_space, max_points, ore, img, points, space)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def compare_colors(colors: str, sim: float, img: Image):
|
|
45
|
+
"""比较图像中指定位置的颜色是否全部匹配。
|
|
46
|
+
|
|
47
|
+
检查图像中多个指定坐标的像素颜色是否都在给定的相似度范围内。
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
colors: 多点颜色描述字符串,格式为 'x1,y1,#RRGGBB|x2,y2,#RRGGBB|...'。
|
|
51
|
+
sim: 颜色相似度,取值范围 0.0 到 1.0。
|
|
52
|
+
img: 待比较的 PIL 图像对象。
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
bool: 所有点的颜色都匹配时返回 True,否则返回 False。
|
|
56
|
+
"""
|
|
57
|
+
sim_space = 255 * (1 - sim)
|
|
58
|
+
cs = colors.split('|')
|
|
59
|
+
points = [None] * len(cs)
|
|
60
|
+
for i in range(len(cs)):
|
|
61
|
+
c = cs[i].split(',')
|
|
62
|
+
points[i] = {'x': int(c[0]), 'y': int(c[1]), 'color': Color(c[2]).to_rgb()}
|
|
63
|
+
|
|
64
|
+
for p in points:
|
|
65
|
+
color = img.getpixel([p['x'], p['y']])
|
|
66
|
+
if not compare_color(color, p['color'], sim_space):
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
return True
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def native_find_colors(sim: float, max_points: int, ore: int, img: Image, points: list, space: int) -> list:
|
|
73
|
+
"""原生多点颜色查找的核心实现。
|
|
74
|
+
|
|
75
|
+
遍历图像像素,按照指定的扫描方向查找与多点颜色模式匹配的位置。
|
|
76
|
+
支持 8 种不同的扫描方向(左上到右下、右下到左上等)。
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
sim: 颜色容差值(已转换为 0-255 范围),表示允许的最大颜色差异。
|
|
80
|
+
max_points: 最大返回匹配点数,-1 表示不限制。
|
|
81
|
+
ore: 扫描方向,取值 1-8:
|
|
82
|
+
1 - 从左到右,从上到下;
|
|
83
|
+
2 - 从上到下,从左到右;
|
|
84
|
+
3 - 从上到下,从右到左;
|
|
85
|
+
4 - 从右到左,从上到下;
|
|
86
|
+
5 - 从右到左,从下到上;
|
|
87
|
+
6 - 从下到上,从右到左;
|
|
88
|
+
7 - 从下到上,从左到右;
|
|
89
|
+
8 - 从左到右,从下到上。
|
|
90
|
+
img: 待搜索的 PIL 图像对象。
|
|
91
|
+
points: 多点颜色描述列表,每个元素为包含 'x'、'y'、'color' 的字典。
|
|
92
|
+
space: 找到匹配后的排除间距。
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
list: 匹配到的 Point 坐标点列表。
|
|
96
|
+
"""
|
|
97
|
+
width = img.width
|
|
98
|
+
height = img.height
|
|
99
|
+
pixs = list(img.getdata())
|
|
100
|
+
|
|
101
|
+
# print(len(pixs), width, height)
|
|
102
|
+
|
|
103
|
+
fcs = []
|
|
104
|
+
|
|
105
|
+
# print(ore)
|
|
106
|
+
|
|
107
|
+
if ore == 1:
|
|
108
|
+
for w in range(width):
|
|
109
|
+
for h in range(height):
|
|
110
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
111
|
+
fcs.append(Point(w, h))
|
|
112
|
+
if len(fcs) >= max_points != -1:
|
|
113
|
+
return fcs
|
|
114
|
+
space_image(pixs, space, width, height, w, h)
|
|
115
|
+
|
|
116
|
+
if ore == 2:
|
|
117
|
+
for h in range(height):
|
|
118
|
+
for w in range(width):
|
|
119
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
120
|
+
fcs.append(Point(w, h))
|
|
121
|
+
if len(fcs) >= max_points != -1:
|
|
122
|
+
return fcs
|
|
123
|
+
space_image(pixs, space, width, height, w, h)
|
|
124
|
+
|
|
125
|
+
if ore == 3:
|
|
126
|
+
for h in range(height):
|
|
127
|
+
for w in reversed(range(width)):
|
|
128
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
129
|
+
fcs.append(Point(w, h))
|
|
130
|
+
if len(fcs) >= max_points != -1:
|
|
131
|
+
return fcs
|
|
132
|
+
space_image(pixs, space, width, height, w, h)
|
|
133
|
+
|
|
134
|
+
if ore == 4:
|
|
135
|
+
for w in reversed(range(width)):
|
|
136
|
+
for h in range(height):
|
|
137
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
138
|
+
fcs.append(Point(w, h))
|
|
139
|
+
if len(fcs) >= max_points != -1:
|
|
140
|
+
return fcs
|
|
141
|
+
space_image(pixs, space, width, height, w, h)
|
|
142
|
+
|
|
143
|
+
if ore == 5:
|
|
144
|
+
for w in reversed(range(width)):
|
|
145
|
+
for h in reversed(range(height)):
|
|
146
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
147
|
+
fcs.append(Point(w, h))
|
|
148
|
+
if len(fcs) >= max_points != -1:
|
|
149
|
+
return fcs
|
|
150
|
+
space_image(pixs, space, width, height, w, h)
|
|
151
|
+
|
|
152
|
+
if ore == 6:
|
|
153
|
+
for h in reversed(range(height)):
|
|
154
|
+
for w in reversed(range(width)):
|
|
155
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
156
|
+
fcs.append(Point(w, h))
|
|
157
|
+
if len(fcs) >= max_points != -1:
|
|
158
|
+
return fcs
|
|
159
|
+
space_image(pixs, space, width, height, w, h)
|
|
160
|
+
|
|
161
|
+
if ore == 7:
|
|
162
|
+
for h in reversed(range(height)):
|
|
163
|
+
for w in range(width):
|
|
164
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
165
|
+
fcs.append(Point(w, h))
|
|
166
|
+
if len(fcs) >= max_points != -1:
|
|
167
|
+
return fcs
|
|
168
|
+
space_image(pixs, space, width, height, w, h)
|
|
169
|
+
|
|
170
|
+
if ore == 8:
|
|
171
|
+
for w in range(width):
|
|
172
|
+
for h in reversed(range(height)):
|
|
173
|
+
if check_color(width, height, pixs, w, h, points, sim):
|
|
174
|
+
fcs.append(Point(w, h))
|
|
175
|
+
if len(fcs) >= max_points != -1:
|
|
176
|
+
return fcs
|
|
177
|
+
space_image(pixs, space, width, height, w, h)
|
|
178
|
+
|
|
179
|
+
return fcs
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def space_image(pixs, space, width, height, w, h):
|
|
183
|
+
"""将匹配点周围区域的像素标记为无效。
|
|
184
|
+
|
|
185
|
+
在找到一个匹配点后,将其周围指定范围内的像素设置为 [-1, -1, -1],
|
|
186
|
+
防止在同一区域内重复匹配。
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
pixs: 图像像素数据列表,每个元素为 [R, G, B]。
|
|
190
|
+
space: 排除的间距范围(像素数)。
|
|
191
|
+
width: 图像宽度。
|
|
192
|
+
height: 图像高度。
|
|
193
|
+
w: 匹配点的横坐标。
|
|
194
|
+
h: 匹配点的纵坐标。
|
|
195
|
+
"""
|
|
196
|
+
x = w - space
|
|
197
|
+
while x < w + space:
|
|
198
|
+
x = x + 1
|
|
199
|
+
if -1 < x < width:
|
|
200
|
+
y = h - space
|
|
201
|
+
while y < h + space:
|
|
202
|
+
y = y + 1
|
|
203
|
+
if x > -1 and y < height:
|
|
204
|
+
pixs[get_pix_forxy(width, x, y)] = [-1, -1, -1]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def check_color(width, height, pixs, x, y, points, sim):
|
|
208
|
+
"""检查指定位置是否满足多点颜色匹配条件。
|
|
209
|
+
|
|
210
|
+
以 (x, y) 为基准点,检查该点及所有偏移点的颜色是否都在容差范围内。
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
width: 图像宽度。
|
|
214
|
+
height: 图像高度。
|
|
215
|
+
pixs: 图像像素数据列表。
|
|
216
|
+
x: 基准点横坐标。
|
|
217
|
+
y: 基准点纵坐标。
|
|
218
|
+
points: 多点颜色描述列表,第一个为基准点,后续为偏移点。
|
|
219
|
+
sim: 颜色容差值(0-255 范围)。
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
bool: 所有点都匹配时返回 True,否则返回 False。
|
|
223
|
+
"""
|
|
224
|
+
if compare_color(pixs[get_pix_forxy(width, x, y)], points[0]['color'], sim):
|
|
225
|
+
|
|
226
|
+
i = 1
|
|
227
|
+
while i < len(points):
|
|
228
|
+
nx = points[i]['x'] + x
|
|
229
|
+
ny = points[i]['y'] + y
|
|
230
|
+
|
|
231
|
+
if nx < 0 or ny < 0 or nx >= width or ny >= height:
|
|
232
|
+
return False
|
|
233
|
+
|
|
234
|
+
if not (compare_color(pixs[get_pix_forxy(width, nx, ny)], points[i]['color'], sim)):
|
|
235
|
+
return False
|
|
236
|
+
|
|
237
|
+
i = i + 1
|
|
238
|
+
|
|
239
|
+
return True
|
|
240
|
+
|
|
241
|
+
return False
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def get_pix_forxy(width, x, y):
|
|
245
|
+
"""根据二维坐标计算像素在一维数组中的索引。
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
width: 图像宽度。
|
|
249
|
+
x: 横坐标。
|
|
250
|
+
y: 纵坐标。
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
int: 像素在一维像素数组中的索引位置。
|
|
254
|
+
"""
|
|
255
|
+
return width * y + x
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def compare_color(c1, c2, sim):
|
|
259
|
+
"""比较两个颜色是否在容差范围内相似。
|
|
260
|
+
|
|
261
|
+
逐通道(R、G、B)比较两个颜色值的差异,判断是否在允许的容差范围内。
|
|
262
|
+
如果 c1 已被标记为无效([-1, -1, -1]),则直接返回 False。
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
c1: 第一个颜色值,格式为 [R, G, B]。
|
|
266
|
+
c2: 第二个颜色值,格式为 [R, G, B]。
|
|
267
|
+
sim: 颜色容差值(0-255 范围),每个通道允许的最大差异。
|
|
268
|
+
|
|
269
|
+
Returns:
|
|
270
|
+
bool: 两个颜色在容差范围内相似返回 True,否则返回 False。
|
|
271
|
+
"""
|
|
272
|
+
if c1[0] == -1:
|
|
273
|
+
return False
|
|
274
|
+
|
|
275
|
+
# print(c1,c2)
|
|
276
|
+
|
|
277
|
+
if abs(c1[0] - c2[0]) <= sim and abs(c1[1] - c2[1]) <= sim and abs(c1[2] - c2[2]) <= sim:
|
|
278
|
+
return True
|
|
279
|
+
|
|
280
|
+
return False
|