python——识别图中文字
纯干货直接上代码
百度:
from aip import AipOcr config = { 'appId': '', 'apiKey': '', 'secretKey': '' } client = AipOcr(**config) def get_file_content(file): with open(file, 'rb') as fp: return fp.read() def img_to_str(image_path): image = get_file_content(image_path) image = image.content result = client.basicAccurate(image) if 'words_result' in result: return '\n'.join([w['words'] for w in result['words_result']])
谷歌:
# open image image = Image.open('') code = pytesseract.image_to_string(image, lang='chi_sim') print(code)