-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutter.py
More file actions
31 lines (29 loc) · 852 Bytes
/
cutter.py
File metadata and controls
31 lines (29 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import glob
import torch
import torchvision
from PIL import Image
import util
model = torch.load("captcha-bound.pt").to("cpu")
window_size = 16
img_width = 90
img_height = 30
dir_path = r'E:\PycharmProject\Captcha\download\*.*'
save_path = "E:\\PycharmProject\\Captcha\\download\\cut\\"
prefix = "cuta_"
res = glob.glob(dir_path)
cnt = 0
for file in res:
img = Image.open(file).convert("L")
i = 0
while i <= img_width - window_size:
image = util.cut_img(img, i, window_size, img_height)
tmp_img = torchvision.transforms.ToTensor()(util.resize_fit(image, 32)).unsqueeze(0)
pred = model(tmp_img).argmax(dim=1).numpy()[0]
if pred == 1:
i += window_size
image.save(save_path + prefix + str(cnt) + ".jpg")
cnt += 1
else:
i += 1
print(cnt)
# break