zoukankan      html  css  js  c++  java
  • 【人工智能】使用百度api批量识别图片上的文字,进阶版

    人工智能大法好,使用百度api批量识别图片上的文字:

    这是是批量识别,统统放进一个文件夹就OK啦~

    from aip import AipOcr  
    import os
    
     
    APP_ID = '?'  
    API_KEY = '?'  
    SECRET_KEY = '?'   
    aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
     
    def get_file_content(filePath):  
        with open(filePath, 'rb') as fp:  
            return fp.read()
     
    for root, dirs, files in os.walk(".", topdown=False):
        for name in files:
            if 'jpg' in name:
                filePath = os.path.join(root, name)[2:]   
                options = {  
                  'detect_direction': 'true',  
                  'language_type': 'CHN_ENG',  
                }  
                result = aipOcr.webImage(get_file_content(filePath),options)
                print(result)
                for i in result['words_result']:
                    print(i['words'])
    

    运行结果:

    消除恐惧的最好办法是面对恐惧!"这不是什么名
    人毒鸡汤,是最近霸屏B站弹幕的ν奥利给“的励志
    语录。
    奥利给究竟是什么梗?
    奥利给″一词彻底火了。一时间,B站、快手、抖
    音上随处可见关于它的视频。
  • 相关阅读:
    数组与方法
    数据类型
    认识Java(2)
    认识Java(1)
    面试题集锦
    00-python语言介绍
    06-python-生成器、循环器
    00-python-内置函数笔记
    04-python-闭包
    03-python-装饰器
  • 原文地址:https://www.cnblogs.com/helenlee01/p/12617441.html
Copyright © 2011-2022 走看看