Sometimes tesseract does not work well on detecting the words in the picture,especially the colorful words or blurry ones. So I try to find a new way to realize it and there has an baidu’s API which works well.
The official document is here:word detection document
After you sign in the website, you can get three values about the api that will be used in later’s register progress:
APP_ID = '10xxxx57'
API_KEY = 'vxxxxxxxxxxxxxxxxxsZyuwz9yKS2EghBs'
SECRET_KEY = 'm7pjnSNCKZxxxxxxxxxxxxxxxswGmIO35zsi'
then install the Lib:
pip install aip
and you can use the api to detect the words,for example:
from aip import AipOcr
APP_ID = '10xxxx57'
API_KEY = 'vxxxxxxxxxxxxxxxxxsZyuwz9yKS2EghBs'
SECRET_KEY = 'm7pjnSNCKZxxxxxxxxxxxxxxxswGmIO35zsi'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
with open('/Users/zhaoluyang/Desktop/test2.png','rb') as f:
img = f.read()
msg = client.basicGeneral(img)
for i in msg.get('words_result'):
print(i.get('words'))
It works better than tesseract at my test