import json
import os
import requests
import base64
from get_access_token import get_token
'''
通用文字识别(高精度版)
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
access_token = json.loads(get_token())['access_token']
headers = {'content-type': 'application/x-www-form-urlencoded'}
def orc():
global request_url
# 二进制方式打开图片文件
for i in os.listdir("./图片/"):
f = open("./图片/"+i, 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
request_url = request_url + "?access_token=" + access_token
response = requests.post(request_url, data=params, headers=headers)
if response:
# print(response.json()["words_result"])
for w in response.json()["words_result"]:
print(w["words"])