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)

 

参考

↓↓↓↓↓↓↓

 

看这里

posted @ 2019-09-03 19:00  情迷九月  阅读(1007)  评论(0编辑  收藏  举报