1 from aip import AipOcr 2 3 """ 你的 APPID AK SK """ 4 APP_ID = 5 API_KEY = 6 SECRET_KEY = 7 8 client = AipOcr(APP_ID, API_KEY, SECRET_KEY) 9 """ 读取图片 """ 10 def get_file_content(filePath): 11 with open(filePath, 'rb') as fp: 12 return fp.read() 13 14 image = get_file_content(r'D:数学.png') 15 16 """ 调用通用文字识别, 图片参数为本地图片 """ 17 client.basicGeneral(image); 18 19 """ 如果有可选参数 """ 20 options = {} 21 options["language_type"] = "CHN_ENG" 22 options["detect_direction"] = "true" 23 options["detect_language"] = "true" 24 options["probability"] = "true" 25 26 """ 带参数调用通用文字识别, 图片参数为本地图片 """ 27 a=client.basicGeneral(image, options) 28 b=a[ 'words_result'] 29 for i in b: 30 print(i['words'])