首页 Python修行正文

Python 之图片文字识别

欲儿 Python修行 2020-03-14 518 0

没有装aip       请CMD : pip install baidu-aip 



但是你需要先创建百度的API也就是应用

image.png


image.png



来到应用列表

image.png




源代码如下

from aip import AipOcr
import re
""" 你的 APPID AK SK """
APP_ID = '18837678'
API_KEY = 'XIPPUjRrkwMCPuLL46LVQYs0'
SECRET_KEY = 'UOAkABVXI4peyCna31BxPcdGQOOxIeVN'
#对应的值记得替换
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)



""" 读取图片 """
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

image = get_file_content('D://005.JPG')

""" 调用通用文字识别, 图片参数为本地图片 """
client.basicGeneral(image);

""" 如果有可选参数 """
options = {}
options["language_type"] = "CHN_ENG"
options["detect_direction"] = "true"
options["detect_language"] = "true"
options["probability"] = "true"

""" 带参数调用通用文字识别, 图片参数为本地图片 """
a = str(client.basicGeneral(image, options))
b = re.findall(r"'words': '(.*?)'}" ,a)
for result in b :
    print(result)


版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论