-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvertifyCodeImage.py
More file actions
67 lines (53 loc) · 1.45 KB
/
Copy pathvertifyCodeImage.py
File metadata and controls
67 lines (53 loc) · 1.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/8/27
# @Author : lei.X
from PIL import Image
import requests
from io import BytesIO
from pytesseract import image_to_string
import os
import random
import time
def get_time_stamp():
t = time.time()
return str(int(round(t * 1000)))
def getImage():
requests.get("http://sep.ucas.ac.cn/changePic")
response = requests.get("http://sep.ucas.ac.cn/changePic?code="+get_time_stamp())
img = Image.open(BytesIO(response.content))
img.show()
# #降噪处理
# threshold = 140
# table = []
# for i in range(256):
# if i<threshold:
# table.append(0)
# else:
# table.append(1)
# imgry = img.convert('L')
# out = imgry.point(table,'1')
#
# text = image_to_string(out)
# print("test:",text)
def makdir(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
print(path+": create success")
return
print(path + ": exsits")
return
def download_verticy_img(path):
response = requests.get("http://sep.ucas.ac.cn/changePic")
fileName = str(random.randint(0,100000))+".jpg"
with open(path+"/"+fileName,'wb') as f:
f.write(response.content)
if __name__ == '__main__':
# getImage()
path = "/Users/xulei2/Desktop/code"
makdir(path)
for i in range(100):
download_verticy_img(path)