pyxllib 0.3.197__py3-none-any.whl → 3.201.1__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.
- pyxllib/__init__.py +14 -21
- pyxllib/algo/__init__.py +8 -8
- pyxllib/algo/disjoint.py +54 -54
- pyxllib/algo/geo.py +537 -541
- pyxllib/algo/intervals.py +964 -964
- pyxllib/algo/matcher.py +389 -389
- pyxllib/algo/newbie.py +166 -166
- pyxllib/algo/pupil.py +629 -629
- pyxllib/algo/shapelylib.py +67 -67
- pyxllib/algo/specialist.py +241 -241
- pyxllib/algo/stat.py +494 -494
- pyxllib/algo/treelib.py +145 -149
- pyxllib/algo/unitlib.py +62 -66
- pyxllib/autogui/__init__.py +5 -5
- pyxllib/autogui/activewin.py +246 -246
- pyxllib/autogui/all.py +9 -9
- pyxllib/autogui/autogui.py +846 -852
- pyxllib/autogui/uiautolib.py +362 -362
- pyxllib/autogui/virtualkey.py +102 -102
- pyxllib/autogui/wechat.py +827 -827
- pyxllib/autogui/wechat_msg.py +421 -421
- pyxllib/autogui/wxautolib.py +84 -84
- pyxllib/cv/__init__.py +5 -5
- pyxllib/cv/expert.py +267 -267
- pyxllib/cv/imfile.py +159 -159
- pyxllib/cv/imhash.py +39 -39
- pyxllib/cv/pupil.py +9 -9
- pyxllib/cv/rgbfmt.py +1525 -1525
- pyxllib/cv/slidercaptcha.py +137 -137
- pyxllib/cv/trackbartools.py +251 -251
- pyxllib/cv/xlcvlib.py +1040 -1040
- pyxllib/cv/xlpillib.py +423 -423
- pyxllib/data/echarts.py +236 -240
- pyxllib/data/jsonlib.py +85 -89
- pyxllib/data/oss.py +72 -72
- pyxllib/data/pglib.py +1111 -1127
- pyxllib/data/sqlite.py +568 -568
- pyxllib/data/sqllib.py +297 -297
- pyxllib/ext/JLineViewer.py +505 -505
- pyxllib/ext/__init__.py +6 -6
- pyxllib/ext/demolib.py +251 -246
- pyxllib/ext/drissionlib.py +277 -277
- pyxllib/ext/kq5034lib.py +12 -12
- pyxllib/ext/qt.py +449 -449
- pyxllib/ext/robustprocfile.py +493 -497
- pyxllib/ext/seleniumlib.py +76 -76
- pyxllib/ext/tk.py +173 -173
- pyxllib/ext/unixlib.py +821 -827
- pyxllib/ext/utools.py +345 -351
- pyxllib/ext/webhook.py +124 -119
- pyxllib/ext/win32lib.py +40 -40
- pyxllib/ext/wjxlib.py +91 -88
- pyxllib/ext/wpsapi.py +124 -124
- pyxllib/ext/xlwork.py +9 -9
- pyxllib/ext/yuquelib.py +1110 -1105
- pyxllib/file/__init__.py +17 -17
- pyxllib/file/docxlib.py +757 -761
- pyxllib/file/gitlib.py +309 -309
- pyxllib/file/libreoffice.py +165 -165
- pyxllib/file/movielib.py +144 -148
- pyxllib/file/newbie.py +10 -10
- pyxllib/file/onenotelib.py +1469 -1469
- pyxllib/file/packlib/__init__.py +330 -330
- pyxllib/file/packlib/zipfile.py +2441 -2441
- pyxllib/file/pdflib.py +422 -426
- pyxllib/file/pupil.py +185 -185
- pyxllib/file/specialist/__init__.py +681 -685
- pyxllib/file/specialist/dirlib.py +799 -799
- pyxllib/file/specialist/download.py +193 -193
- pyxllib/file/specialist/filelib.py +2825 -2829
- pyxllib/file/xlsxlib.py +3122 -3131
- pyxllib/file/xlsyncfile.py +341 -341
- pyxllib/prog/__init__.py +5 -5
- pyxllib/prog/cachetools.py +58 -64
- pyxllib/prog/deprecatedlib.py +233 -233
- pyxllib/prog/filelock.py +42 -42
- pyxllib/prog/ipyexec.py +253 -253
- pyxllib/prog/multiprogs.py +940 -940
- pyxllib/prog/newbie.py +451 -451
- pyxllib/prog/pupil.py +1208 -1197
- pyxllib/prog/sitepackages.py +33 -33
- pyxllib/prog/specialist/__init__.py +348 -391
- pyxllib/prog/specialist/bc.py +203 -203
- pyxllib/prog/specialist/browser.py +497 -497
- pyxllib/prog/specialist/common.py +347 -347
- pyxllib/prog/specialist/datetime.py +198 -198
- pyxllib/prog/specialist/tictoc.py +240 -240
- pyxllib/prog/specialist/xllog.py +180 -180
- pyxllib/prog/xlosenv.py +110 -108
- pyxllib/stdlib/__init__.py +17 -17
- pyxllib/stdlib/tablepyxl/__init__.py +10 -10
- pyxllib/stdlib/tablepyxl/style.py +303 -303
- pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
- pyxllib/text/__init__.py +8 -8
- pyxllib/text/ahocorasick.py +36 -39
- pyxllib/text/airscript.js +754 -744
- pyxllib/text/charclasslib.py +121 -121
- pyxllib/text/jiebalib.py +267 -267
- pyxllib/text/jinjalib.py +27 -32
- pyxllib/text/jsa_ai_prompt.md +271 -271
- pyxllib/text/jscode.py +922 -922
- pyxllib/text/latex/__init__.py +158 -158
- pyxllib/text/levenshtein.py +303 -303
- pyxllib/text/nestenv.py +1215 -1215
- pyxllib/text/newbie.py +300 -300
- pyxllib/text/pupil/__init__.py +8 -8
- pyxllib/text/pupil/common.py +1121 -1121
- pyxllib/text/pupil/xlalign.py +326 -326
- pyxllib/text/pycode.py +47 -47
- pyxllib/text/specialist/__init__.py +8 -8
- pyxllib/text/specialist/common.py +112 -112
- pyxllib/text/specialist/ptag.py +186 -186
- pyxllib/text/spellchecker.py +172 -172
- pyxllib/text/templates/echart_base.html +10 -10
- pyxllib/text/templates/highlight_code.html +16 -16
- pyxllib/text/templates/latex_editor.html +102 -102
- pyxllib/text/vbacode.py +17 -17
- pyxllib/text/xmllib.py +741 -747
- pyxllib/xl.py +42 -39
- pyxllib/xlcv.py +17 -17
- pyxllib-3.201.1.dist-info/METADATA +296 -0
- pyxllib-3.201.1.dist-info/RECORD +125 -0
- {pyxllib-0.3.197.dist-info → pyxllib-3.201.1.dist-info}/licenses/LICENSE +190 -190
- pyxllib/ext/old.py +0 -663
- pyxllib-0.3.197.dist-info/METADATA +0 -48
- pyxllib-0.3.197.dist-info/RECORD +0 -126
- {pyxllib-0.3.197.dist-info → pyxllib-3.201.1.dist-info}/WHEEL +0 -0
pyxllib/cv/slidercaptcha.py
CHANGED
@@ -1,137 +1,137 @@
|
|
1
|
-
import os
|
2
|
-
import cv2
|
3
|
-
import numpy as np
|
4
|
-
from xlproject.code4101 import XlPath
|
5
|
-
|
6
|
-
from pyxllib.file.specialist import download_file
|
7
|
-
from pyxllib.prog.pupil import is_url
|
8
|
-
|
9
|
-
|
10
|
-
class SliderCaptchaLocator:
|
11
|
-
""" 滑动验证码的位置定位
|
12
|
-
|
13
|
-
由于缺口一般是一个黑底图,整体颜色是偏暗的,可以利用这个特性来定位列所在位置
|
14
|
-
"""
|
15
|
-
|
16
|
-
def __init__(self, background_image_path, slider_image_path=None):
|
17
|
-
"""
|
18
|
-
:param background_image_path: 背景主图片
|
19
|
-
:param slider_image_path: 滑动条图片
|
20
|
-
"""
|
21
|
-
# 支持输入是url的情况
|
22
|
-
if is_url(background_image_path):
|
23
|
-
background_image_path = download_file(background_image_path, temp=True, ext='.png')
|
24
|
-
if is_url(slider_image_path):
|
25
|
-
slider_image_path = download_file(slider_image_path, temp=True, ext='.png')
|
26
|
-
# 初始化图片等数据
|
27
|
-
self.image_path = background_image_path
|
28
|
-
self.image = cv2.imread(self.image_path)
|
29
|
-
self.darkest_rows = None
|
30
|
-
self.column_averages = None
|
31
|
-
self.enhanced_averages = None
|
32
|
-
self.radius = 24
|
33
|
-
if slider_image_path is not None:
|
34
|
-
# 先读取图片
|
35
|
-
template_image = cv2.imread(slider_image_path)
|
36
|
-
# 取图片宽度的40%作为radius
|
37
|
-
self.radius = int(template_image.shape[1] * 0.4)
|
38
|
-
|
39
|
-
def select_darkest_part_rows(self, fraction=0.1):
|
40
|
-
"""
|
41
|
-
选择最暗的部分行,供下游计算列的平均暗度
|
42
|
-
|
43
|
-
:param float fraction: 最暗行的比例
|
44
|
-
:return: 最暗行的图像部分
|
45
|
-
"""
|
46
|
-
if self.darkest_rows is None:
|
47
|
-
average_row_values = np.mean(self.image, axis=(1, 2))
|
48
|
-
threshold_index = int(len(average_row_values) * fraction)
|
49
|
-
darkest_indices = np.argsort(average_row_values)[:threshold_index]
|
50
|
-
self.darkest_rows = self.image[darkest_indices]
|
51
|
-
return self.darkest_rows
|
52
|
-
|
53
|
-
def calculate_column_averages(self):
|
54
|
-
"""
|
55
|
-
计算列的平均强度。
|
56
|
-
|
57
|
-
:return: 列的平均强度
|
58
|
-
"""
|
59
|
-
if self.column_averages is None:
|
60
|
-
rows = self.select_darkest_part_rows()
|
61
|
-
column_values = np.mean(rows, axis=0)
|
62
|
-
column_intensity = np.mean(column_values, axis=1)
|
63
|
-
min_val, max_val = np.min(column_intensity), np.max(column_intensity)
|
64
|
-
self.column_averages = ((column_intensity - min_val) / (max_val - min_val) * 255).astype(
|
65
|
-
np.uint8) if max_val != min_val else np.zeros_like(column_intensity)
|
66
|
-
return self.column_averages
|
67
|
-
|
68
|
-
def enhance_column_averages(self):
|
69
|
-
"""
|
70
|
-
增强列平均值,利用验证码的黑度图的对称性,进行一个增强,使得其他非验证码的零散黑条变白
|
71
|
-
|
72
|
-
:param int radius: 对比半径,这个建议设成模版图宽度的40%~50%
|
73
|
-
:return: 增强后的列平均值
|
74
|
-
"""
|
75
|
-
if self.enhanced_averages is None:
|
76
|
-
averages = self.calculate_column_averages()
|
77
|
-
length = len(averages)
|
78
|
-
enhanced = np.zeros_like(averages)
|
79
|
-
for i in range(length):
|
80
|
-
max_value = averages[i]
|
81
|
-
for j in range(1, self.radius // 2 + 1):
|
82
|
-
if i - j >= 0 and i + j < length:
|
83
|
-
max_value = max(max_value, abs(int(averages[i - j]) - int(averages[i + j])))
|
84
|
-
enhanced[i] = max_value
|
85
|
-
self.enhanced_averages = enhanced
|
86
|
-
return self.enhanced_averages
|
87
|
-
|
88
|
-
def find_captcha_position(self, threshold=50):
|
89
|
-
"""
|
90
|
-
查找验证码的位置。
|
91
|
-
|
92
|
-
:param int threshold: 达到多少像素后,开始计算中位数
|
93
|
-
:return: 验证码的列中心位置
|
94
|
-
"""
|
95
|
-
intensities = self.enhance_column_averages()
|
96
|
-
indices = []
|
97
|
-
for intensity in range(256):
|
98
|
-
new_indices = np.where(intensities == intensity)[0]
|
99
|
-
if len(indices) + len(new_indices) > threshold:
|
100
|
-
indices.extend(new_indices[:threshold - len(indices)])
|
101
|
-
break
|
102
|
-
indices.extend(new_indices)
|
103
|
-
return int(np.median(indices))
|
104
|
-
|
105
|
-
def draw_red_line(self, position, line_thickness=3):
|
106
|
-
"""
|
107
|
-
在图像上绘制红线。
|
108
|
-
|
109
|
-
:param int position: 红线位置
|
110
|
-
:param int line_thickness: 线宽
|
111
|
-
:return: 绘制红线后的图像
|
112
|
-
"""
|
113
|
-
gray_image = np.tile(self.calculate_column_averages(), (100, 1)).astype(np.uint8)
|
114
|
-
color_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
|
115
|
-
cv2.line(color_image, (position, 0), (position, gray_image.shape[0]), (0, 0, 255), line_thickness)
|
116
|
-
return color_image
|
117
|
-
|
118
|
-
def debug(self):
|
119
|
-
position = self.find_captcha_position()
|
120
|
-
final_image = self.draw_red_line(position)
|
121
|
-
cv2.imshow('Image with Red Line', final_image)
|
122
|
-
cv2.waitKey(0)
|
123
|
-
cv2.destroyAllWindows()
|
124
|
-
|
125
|
-
|
126
|
-
def main():
|
127
|
-
os.chdir(XlPath.desktop())
|
128
|
-
locator = SliderCaptchaLocator('cap_union_new_getcapbysig.png')
|
129
|
-
position = locator.find_captcha_position()
|
130
|
-
final_image = locator.draw_red_line(position)
|
131
|
-
cv2.imshow('Image with Red Line', final_image)
|
132
|
-
cv2.waitKey(0)
|
133
|
-
cv2.destroyAllWindows()
|
134
|
-
|
135
|
-
|
136
|
-
if __name__ == '__main__':
|
137
|
-
main()
|
1
|
+
import os
|
2
|
+
import cv2
|
3
|
+
import numpy as np
|
4
|
+
from xlproject.code4101 import XlPath
|
5
|
+
|
6
|
+
from pyxllib.file.specialist import download_file
|
7
|
+
from pyxllib.prog.pupil import is_url
|
8
|
+
|
9
|
+
|
10
|
+
class SliderCaptchaLocator:
|
11
|
+
""" 滑动验证码的位置定位
|
12
|
+
|
13
|
+
由于缺口一般是一个黑底图,整体颜色是偏暗的,可以利用这个特性来定位列所在位置
|
14
|
+
"""
|
15
|
+
|
16
|
+
def __init__(self, background_image_path, slider_image_path=None):
|
17
|
+
"""
|
18
|
+
:param background_image_path: 背景主图片
|
19
|
+
:param slider_image_path: 滑动条图片
|
20
|
+
"""
|
21
|
+
# 支持输入是url的情况
|
22
|
+
if is_url(background_image_path):
|
23
|
+
background_image_path = download_file(background_image_path, temp=True, ext='.png')
|
24
|
+
if is_url(slider_image_path):
|
25
|
+
slider_image_path = download_file(slider_image_path, temp=True, ext='.png')
|
26
|
+
# 初始化图片等数据
|
27
|
+
self.image_path = background_image_path
|
28
|
+
self.image = cv2.imread(self.image_path)
|
29
|
+
self.darkest_rows = None
|
30
|
+
self.column_averages = None
|
31
|
+
self.enhanced_averages = None
|
32
|
+
self.radius = 24
|
33
|
+
if slider_image_path is not None:
|
34
|
+
# 先读取图片
|
35
|
+
template_image = cv2.imread(slider_image_path)
|
36
|
+
# 取图片宽度的40%作为radius
|
37
|
+
self.radius = int(template_image.shape[1] * 0.4)
|
38
|
+
|
39
|
+
def select_darkest_part_rows(self, fraction=0.1):
|
40
|
+
"""
|
41
|
+
选择最暗的部分行,供下游计算列的平均暗度
|
42
|
+
|
43
|
+
:param float fraction: 最暗行的比例
|
44
|
+
:return: 最暗行的图像部分
|
45
|
+
"""
|
46
|
+
if self.darkest_rows is None:
|
47
|
+
average_row_values = np.mean(self.image, axis=(1, 2))
|
48
|
+
threshold_index = int(len(average_row_values) * fraction)
|
49
|
+
darkest_indices = np.argsort(average_row_values)[:threshold_index]
|
50
|
+
self.darkest_rows = self.image[darkest_indices]
|
51
|
+
return self.darkest_rows
|
52
|
+
|
53
|
+
def calculate_column_averages(self):
|
54
|
+
"""
|
55
|
+
计算列的平均强度。
|
56
|
+
|
57
|
+
:return: 列的平均强度
|
58
|
+
"""
|
59
|
+
if self.column_averages is None:
|
60
|
+
rows = self.select_darkest_part_rows()
|
61
|
+
column_values = np.mean(rows, axis=0)
|
62
|
+
column_intensity = np.mean(column_values, axis=1)
|
63
|
+
min_val, max_val = np.min(column_intensity), np.max(column_intensity)
|
64
|
+
self.column_averages = ((column_intensity - min_val) / (max_val - min_val) * 255).astype(
|
65
|
+
np.uint8) if max_val != min_val else np.zeros_like(column_intensity)
|
66
|
+
return self.column_averages
|
67
|
+
|
68
|
+
def enhance_column_averages(self):
|
69
|
+
"""
|
70
|
+
增强列平均值,利用验证码的黑度图的对称性,进行一个增强,使得其他非验证码的零散黑条变白
|
71
|
+
|
72
|
+
:param int radius: 对比半径,这个建议设成模版图宽度的40%~50%
|
73
|
+
:return: 增强后的列平均值
|
74
|
+
"""
|
75
|
+
if self.enhanced_averages is None:
|
76
|
+
averages = self.calculate_column_averages()
|
77
|
+
length = len(averages)
|
78
|
+
enhanced = np.zeros_like(averages)
|
79
|
+
for i in range(length):
|
80
|
+
max_value = averages[i]
|
81
|
+
for j in range(1, self.radius // 2 + 1):
|
82
|
+
if i - j >= 0 and i + j < length:
|
83
|
+
max_value = max(max_value, abs(int(averages[i - j]) - int(averages[i + j])))
|
84
|
+
enhanced[i] = max_value
|
85
|
+
self.enhanced_averages = enhanced
|
86
|
+
return self.enhanced_averages
|
87
|
+
|
88
|
+
def find_captcha_position(self, threshold=50):
|
89
|
+
"""
|
90
|
+
查找验证码的位置。
|
91
|
+
|
92
|
+
:param int threshold: 达到多少像素后,开始计算中位数
|
93
|
+
:return: 验证码的列中心位置
|
94
|
+
"""
|
95
|
+
intensities = self.enhance_column_averages()
|
96
|
+
indices = []
|
97
|
+
for intensity in range(256):
|
98
|
+
new_indices = np.where(intensities == intensity)[0]
|
99
|
+
if len(indices) + len(new_indices) > threshold:
|
100
|
+
indices.extend(new_indices[:threshold - len(indices)])
|
101
|
+
break
|
102
|
+
indices.extend(new_indices)
|
103
|
+
return int(np.median(indices))
|
104
|
+
|
105
|
+
def draw_red_line(self, position, line_thickness=3):
|
106
|
+
"""
|
107
|
+
在图像上绘制红线。
|
108
|
+
|
109
|
+
:param int position: 红线位置
|
110
|
+
:param int line_thickness: 线宽
|
111
|
+
:return: 绘制红线后的图像
|
112
|
+
"""
|
113
|
+
gray_image = np.tile(self.calculate_column_averages(), (100, 1)).astype(np.uint8)
|
114
|
+
color_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
|
115
|
+
cv2.line(color_image, (position, 0), (position, gray_image.shape[0]), (0, 0, 255), line_thickness)
|
116
|
+
return color_image
|
117
|
+
|
118
|
+
def debug(self):
|
119
|
+
position = self.find_captcha_position()
|
120
|
+
final_image = self.draw_red_line(position)
|
121
|
+
cv2.imshow('Image with Red Line', final_image)
|
122
|
+
cv2.waitKey(0)
|
123
|
+
cv2.destroyAllWindows()
|
124
|
+
|
125
|
+
|
126
|
+
def main():
|
127
|
+
os.chdir(XlPath.desktop())
|
128
|
+
locator = SliderCaptchaLocator('cap_union_new_getcapbysig.png')
|
129
|
+
position = locator.find_captcha_position()
|
130
|
+
final_image = locator.draw_red_line(position)
|
131
|
+
cv2.imshow('Image with Red Line', final_image)
|
132
|
+
cv2.waitKey(0)
|
133
|
+
cv2.destroyAllWindows()
|
134
|
+
|
135
|
+
|
136
|
+
if __name__ == '__main__':
|
137
|
+
main()
|