質問編集履歴
1
ソースコードを付け加えました
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,157 @@
|
|
24
24
|
|
25
25
|
```python
|
26
26
|
|
27
|
+
#!/usr/bin/python
|
28
|
+
|
29
|
+
#coding:utf-8
|
30
|
+
|
31
|
+
import base64
|
32
|
+
|
33
|
+
import json
|
34
|
+
|
35
|
+
import cv2
|
36
|
+
|
37
|
+
from requests import Request, Session
|
38
|
+
|
39
|
+
from bs4 import BeautifulSoup
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
if __name__ == '__main__':
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
im = cv2.imread('/Users/yamamotoyuuki/Desktop/python/ aiu.png',0)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
dat = im[200]
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
path = "/Users/yamamotoyuuki/Desktop/python/ aiu.png"
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
def recognize_captcha(str_image_path):
|
64
|
+
|
65
|
+
bin_captcha = open(str_image_path, 'rb').read()
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
#str_encode_file = base64.b64encode(bin_captcha)
|
70
|
+
|
71
|
+
str_encode_file = base64.b64encode(bin_captcha).decode("utf-8")
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
str_url = "https://vision.googleapis.com/v1/images:annotate?key="
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
str_api_key = "ここは鍵です"
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
str_headers = {'Content-Type': 'application/json'}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
str_json_data = {
|
90
|
+
|
91
|
+
'requests': [
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
'image': {
|
96
|
+
|
97
|
+
'content': str_encode_file
|
98
|
+
|
99
|
+
},
|
100
|
+
|
101
|
+
'features': [
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
'type': "TEXT_DETECTION",
|
106
|
+
|
107
|
+
'maxResults': 10
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
]
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
]
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
print("begin request")
|
122
|
+
|
123
|
+
obj_session = Session()
|
124
|
+
|
125
|
+
obj_request = Request("POST",
|
126
|
+
|
127
|
+
str_url + str_api_key,
|
128
|
+
|
129
|
+
data=json.dumps(str_json_data),
|
130
|
+
|
131
|
+
headers=str_headers
|
132
|
+
|
133
|
+
)
|
134
|
+
|
135
|
+
obj_prepped = obj_session.prepare_request(obj_request)
|
136
|
+
|
137
|
+
obj_response = obj_session.send(obj_prepped,
|
138
|
+
|
139
|
+
verify=True,
|
140
|
+
|
141
|
+
timeout=60
|
142
|
+
|
143
|
+
)
|
144
|
+
|
145
|
+
print("end request")
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
if obj_response.status_code == 200:
|
150
|
+
|
151
|
+
#print (obj_response.text)
|
152
|
+
|
153
|
+
with open('data.json', 'w') as outfile:
|
154
|
+
|
155
|
+
json.dump(obj_response.text, outfile)
|
156
|
+
|
157
|
+
return obj_response.text
|
158
|
+
|
27
|
-
|
159
|
+
else:
|
160
|
+
|
161
|
+
return "error"
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
if __name__ == '__main__':
|
166
|
+
|
167
|
+
data = json.loads(recognize_captcha(path))
|
168
|
+
|
169
|
+
data = data["responses"]
|
170
|
+
|
171
|
+
print(data)
|
172
|
+
|
173
|
+
for i in data:
|
174
|
+
|
175
|
+
print(i["fullTextAnnotation"]["text"])
|
176
|
+
|
177
|
+
|
28
178
|
|
29
179
|
```
|
30
180
|
|
@@ -34,12 +184,14 @@
|
|
34
184
|
|
35
185
|
|
36
186
|
|
187
|
+
下から3行目をprint(int(data) * 2)にしてみましたがだめでした
|
188
|
+
|
37
|
-
|
189
|
+
数字認識のやり方をかえるべきなんでしょうか。。
|
38
190
|
|
39
191
|
|
40
192
|
|
41
|
-
### 補足情報(FW/ツールのバージョンなど)
|
193
|
+
### 補足情報(FW/ツールのバージョンなど)
|
42
194
|
|
43
195
|
|
44
196
|
|
45
|
-
こ
|
197
|
+
プログラミング始めて1ヶ月もたってない学生で、この質問サイトも始めて使うのでよくわかってません。失礼があれば言ってください。
|