質問編集履歴
3
変更前の写真
test
CHANGED
File without changes
|
test
CHANGED
@@ -287,3 +287,15 @@
|
|
287
287
|
|
288
288
|
|
289
289
|
上記でも出力が同じでした。
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
変更前の写真は以下でした。
|
296
|
+
|
297
|
+
![イメージ説明](562fe54ba4cd1ce9c73212a0f24b4a78.png)
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
ひらがなは読めないんでしょうか。
|
2
追記2
test
CHANGED
File without changes
|
test
CHANGED
@@ -221,3 +221,69 @@
|
|
221
221
|
|
222
222
|
|
223
223
|
これは、そもそも画像が読み込まれていないのでしょうか。
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
すいません、pathを違うもので書いてました。
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
def img_to_base64(filepath):
|
236
|
+
|
237
|
+
filepath = 'img/text-tool03.png'
|
238
|
+
|
239
|
+
with open(filepath, 'rb') as img:
|
240
|
+
|
241
|
+
img_byte = img.read()
|
242
|
+
|
243
|
+
return base64.b64encode(img_byte)
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
# 文字認識させたい画像を./img.pngとする
|
248
|
+
|
249
|
+
filepath = 'img/text-tool03.png'
|
250
|
+
|
251
|
+
img_base64 = img_to_base64(filepath)
|
252
|
+
|
253
|
+
result = request_cloud_vison_api(img_base64)
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
#認識した文字の位置など、すべての情報を出力
|
258
|
+
|
259
|
+
print("{}".format(json.dumps(result, indent=4)))
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
#認識した文字のみを出力
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
# def get_fullTextAnnotation(json_data):
|
268
|
+
|
269
|
+
# text_dict = json.loads(json_data)
|
270
|
+
|
271
|
+
# try:
|
272
|
+
|
273
|
+
# text_r = text_dict["responses"][0]["fullTextAnnotation"]["text"]
|
274
|
+
|
275
|
+
# return print(text_r)
|
276
|
+
|
277
|
+
# except:
|
278
|
+
|
279
|
+
# print(None)
|
280
|
+
|
281
|
+
# return None
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
上記でも出力が同じでした。
|
1
コードを一部変更(追記)
test
CHANGED
File without changes
|
test
CHANGED
@@ -141,3 +141,83 @@
|
|
141
141
|
|
142
142
|
|
143
143
|
宜しくお願い致します。
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
追記
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
# 文字認識させたい画像を./img.pngとする
|
154
|
+
|
155
|
+
filepath = 'img'
|
156
|
+
|
157
|
+
path = os.listdir(filepath)
|
158
|
+
|
159
|
+
new_path = ','.join(path).replace(".DS_Store,","")
|
160
|
+
|
161
|
+
new_dir_path = 'img/' + new_path
|
162
|
+
|
163
|
+
img_base64 = img_to_base64(new_dir_path)
|
164
|
+
|
165
|
+
result = request_cloud_vison_api(img_base64)
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
**#認識した文字の位置など、すべての情報を出力
|
170
|
+
|
171
|
+
print("{}".format(json.dumps(result, indent=4)))**
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
#認識した文字のみを出力
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
# def get_fullTextAnnotation(json_data):
|
180
|
+
|
181
|
+
# text_dict = json.loads(json_data)
|
182
|
+
|
183
|
+
# try:
|
184
|
+
|
185
|
+
# text_r = text_dict["responses"][0]["fullTextAnnotation"]["text"]
|
186
|
+
|
187
|
+
# return print(text_r)
|
188
|
+
|
189
|
+
# except:
|
190
|
+
|
191
|
+
# print(None)
|
192
|
+
|
193
|
+
# return None
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
途中、print("{}".format(json.dumps(result, indent=4)))で出力した結果、以下が出ました。
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
{
|
208
|
+
|
209
|
+
"responses": [
|
210
|
+
|
211
|
+
{}
|
212
|
+
|
213
|
+
]
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
これは、そもそも画像が読み込まれていないのでしょうか。
|