· 7 years ago · Mar 15, 2018, 08:38 PM
1# -*- coding: UTF-8 -*-
2import androidhelper
3from ocr import AipOrc
4
5path="/storage/emulated/0/qpython/tmp.jpg"
6droid = androidhelper.Android()
7droid.cameraInteractiveCapturePicture(path)
8#use baidu-aip to recognise words,need network.
9
10def recogniseText(path):
11 APP_ID = '9851066'
12 API_KEY = 'LUGBatgyRGoerR9FZbV4SQYk'
13 SECRET_KEY = 'fB2MNz1c2UHLTximFlC4laXPg7CVfyjV'
14
15 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
16
17
18 filePath = path
19 def get_file_content(filePath):
20 with open(filePath, 'rb') as fp:
21 return fp.read()
22
23
24 options = {
25 'detect_direction': 'true',
26 'language_type': 'CHN_ENG',
27 }
28 result = aipOcr.basicGeneral(get_file_content(filePath), options)
29 return result["words_result"]
30texts=recogniseText(path)
31for text in texts:
32 droid.ttsSpeak(text['words'])