- 百度智能云的链接:https://link.zhihu.com/?target=https%3A//console.bce.baidu.com/ai/%23/ai/ocr/overview/index
-
将APP_ID、API_KEY、SECRET_KEY换成自己百度云上自己获取的
-
def api_connect(image): APP_ID = '' API_KEY = '' SECRET_KEY = '' client = AipOcr(APP_ID,API_KEY,SECRET_KEY) options = {"detect_direction":"true"} result = client.basicGeneral(image, options) ending = result["words_result"] for word in ending: # print(word) text = word['words'] text = text+'\n' print(text) with open("text.doc", "a") as fp: fp.write(text) print("写入完成") def image_to_words(): dirs = os.listdir(r'C:\Users\Administrator\Desktop\AHNU\图片') print(dirs) for dir in dirs: filepath = f"C:\\Users\\Administrator\\Desktop\\AHNU\\图片\\{dir}" print(filepath) with open(f"C:\\Users\\Administrator\\Desktop\\AHNU\\图片\\{dir}", "rb") as f: image = f.read() api_connect(image) return None if __name__ == "__main__": image_to_words()
识别图片文字,保存成word文档,python实现
最新推荐文章于 2024-10-24 09:50:49 发布