Python制作一个简单的图片文字提取+PDF转WORD的软件 |
您所在的位置:网站首页 › word如何把图片转为可编辑的文字 › Python制作一个简单的图片文字提取+PDF转WORD的软件 |
Python3.6实现图片文字识别和PDF转WORD
图片文字提取
- - 需求来源 - -
- - 代码实现 - -
PDF转WORD
- - 需求来源 - -
- - 代码实现 - -
窗口实现
- - 使用PyQt5创建 - -
- - 使用tkinter 创建 - -
最终实现
- - 实现说明 - -
- - 完整代码(百度AI账号自申)- -
程序打包
- - 使用pyinstaller - -
图片文字提取
- - 需求来源 - -
因为朋友抱怨图片提取文字都是限制图片且付费的,于是就想利用Python开源的优势做一个免费的程序,可以实现图片中文字的提取。 - - 代码实现 - -参考百度图片文字识别过程: https://blog.csdn.net/XnCSD/article/details/80786793 忽略图片压缩过程,只识别一张图片 import sys import os import glob from os import path from aip import AipOcr from PIL import Image def baiduOCR(picfile, outfile): """利用百度api识别文本,并保存提取的文字 picfile: 图片文件名 outfile: 输出文件 """ filename = path.basename(picfile) APP_ID = '***' # 刚才获取的 ID,下同 API_KEY = '***' SECRECT_KEY = '***' client = AipOcr(APP_ID, API_KEY, SECRECT_KEY) i = open(picfile, 'rb') img = i.read() #print("正在识别图片:\t" + filename) message = client.basicGeneral(img) # 通用文字识别,每天 50 000 次免费 #message = client.basicAccurate(img) # 通用文字高精度识别,每天 800 次免费 #print("识别成功!") i.close(); with open(outfile, 'a+') as fo: fo.writelines("+" * 60 + '\n') fo.writelines("识别图片:\t" + filename + "\n" * 2) fo.writelines("文本内容:\n") # 输出文本内容 for text in message.get('words_result'): fo.writelines(text.get('words') + '\n') fo.writelines('\n'*2) #print("文本导出成功!") #print() picfile = 'path of picture' #图片路径 outfile = 'result.txt' if path.exists(outfile): os.remove(outfile) #lb.config(text = "图片识别..."); baiduOCR(picfile, outfile) #lb.config(text = "图片文本提取结束!文本输出结果位于"+outfile+"文件中"); PDF转WORD - - 需求来源 - -微软Office和金山WPS都可以免费实现word转pdf,但是PDF转word文档需要会员或者一定费用实现全部pdf的转换。 一些在线的网站以可完成免费的pdf 转 word: 50M以内的PDF转换: 便捷PDF转换器 == 如果只是想提取PDF中的文字(不包含格式),可以使用此程序进行转换。== - - 代码实现 - - import sys import importlib importlib.reload(sys) from pdfminer.pdfparser import PDFParser,PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |