style: 统一 Ruff 代码格式
This commit is contained in:
@@ -11,6 +11,7 @@ REQUEST_TIMEOUT = (3.05, 12)
|
||||
def pilImgToCv2(img: Image.Image, flag=cv2.COLOR_RGB2BGR):
|
||||
return cv2.cvtColor(np.asarray(img), flag)
|
||||
|
||||
|
||||
# 识别图片缺口返回滑块距离
|
||||
def shibie(img: Image.Image, slice: Image.Image):
|
||||
# 通过 pilImgToCv2 将图片置灰
|
||||
@@ -38,20 +39,70 @@ def shibie(img: Image.Image, slice: Image.Image):
|
||||
# showImg(resultBg) # 可以通过它来看处理后的图片效果
|
||||
return distance
|
||||
|
||||
|
||||
# 还原图片
|
||||
def restore_geetest_image(input_path:str, output_path:str) -> None:
|
||||
def restore_geetest_image(input_path: str, output_path: str) -> None:
|
||||
"""
|
||||
还原极验打乱的验证码图像
|
||||
"""
|
||||
Ut = [
|
||||
39, 38, 48, 49, 41, 40, 46, 47, 35, 34, 50, 51, 33, 32, 28, 29,
|
||||
27, 26, 36, 37, 31, 30, 44, 45, 43, 42, 12, 13, 23, 22, 14, 15,
|
||||
21, 20, 8, 9, 25, 24, 6, 7, 3, 2, 0, 1, 11, 10, 4, 5, 19, 18, 16, 17
|
||||
39,
|
||||
38,
|
||||
48,
|
||||
49,
|
||||
41,
|
||||
40,
|
||||
46,
|
||||
47,
|
||||
35,
|
||||
34,
|
||||
50,
|
||||
51,
|
||||
33,
|
||||
32,
|
||||
28,
|
||||
29,
|
||||
27,
|
||||
26,
|
||||
36,
|
||||
37,
|
||||
31,
|
||||
30,
|
||||
44,
|
||||
45,
|
||||
43,
|
||||
42,
|
||||
12,
|
||||
13,
|
||||
23,
|
||||
22,
|
||||
14,
|
||||
15,
|
||||
21,
|
||||
20,
|
||||
8,
|
||||
9,
|
||||
25,
|
||||
24,
|
||||
6,
|
||||
7,
|
||||
3,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
11,
|
||||
10,
|
||||
4,
|
||||
5,
|
||||
19,
|
||||
18,
|
||||
16,
|
||||
17,
|
||||
]
|
||||
|
||||
# 打开混淆图像
|
||||
img = Image.open(input_path)
|
||||
new_img = Image.new("RGB", (260,160))
|
||||
new_img = Image.new("RGB", (260, 160))
|
||||
r = 160
|
||||
for _ in range(len(Ut)):
|
||||
a = r / 2
|
||||
@@ -63,11 +114,12 @@ def restore_geetest_image(input_path:str, output_path:str) -> None:
|
||||
new_img.save(output_path)
|
||||
logger.debug("图像已还原并保存到: {}", output_path)
|
||||
|
||||
|
||||
# 下载图片
|
||||
def download_picture(bg:str, fullbg:str, slice:str) -> int:
|
||||
def download_picture(bg: str, fullbg: str, slice: str) -> int:
|
||||
for i in range(3):
|
||||
if i == 0:
|
||||
url = "https://static.geetest.com/"+bg
|
||||
url = "https://static.geetest.com/" + bg
|
||||
response = requests.get(url, timeout=REQUEST_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
with open("bg.jpg", "wb") as f:
|
||||
@@ -87,4 +139,4 @@ def download_picture(bg:str, fullbg:str, slice:str) -> int:
|
||||
response.raise_for_status()
|
||||
with open("slice.jpg", "wb") as f:
|
||||
f.write(response.content)
|
||||
return shibie(Image.open('fullbg.jpg'), Image.open('slice.jpg'))
|
||||
return shibie(Image.open("fullbg.jpg"), Image.open("slice.jpg"))
|
||||
|
||||
Reference in New Issue
Block a user