使用pytesseract提取图片文字
效果展示:
(原始图片)
(运行结果)
代码示例:
# -*- coding:utf-8 -*- from PIL import Image import pytesseract def cleanFile(filePath, newFilePath): image = Image.open(filePath) # 对图片进行阈值过滤(低于143的置为黑色,否则为白色) # 相当于对电脑显卡调节对比度(电脑显卡对比度默认为50,我比较习惯于调成53) image = image.point(lambda x: 0 if x < 143 else 255) # 重新保存图片 image.save(newFilePath) image = Image.open(newFilePath) text = pytesseract.image_to_string(image, lang='chi_sim') print(text) if __name__ == "__main__": url = r"D:\图片\励志图片\666.png" new_url = r"D:\图片\励志图片\777.png" cleanFile(url, new_url)
本文来自博客园,作者:数据驱动,转载请注明原文链接:https://www.cnblogs.com/shun7man/p/14425931.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步