当前位置: 首页 > news >正文

纪检监察网站建设方案临沂百度联系方式

纪检监察网站建设方案,临沂百度联系方式,dedecms手机网站仿制,哪些公司做网站好前段时间我写了Python识别拖放的PDF文件再转成文本文件-CSDN博客 最近有2点更新,一是有一些pdf文件转换出来的图片是横的,这样也可以识别文字,但是可能会影响效果,另一个是发现有一些文字识别不出来,看了关于提高Padd…

前段时间我写了Python识别拖放的PDF文件再转成文本文件-CSDN博客

最近有2点更新,一是有一些pdf文件转换出来的图片是横的,这样也可以识别文字,但是可能会影响效果,另一个是发现有一些文字识别不出来,看了关于提高PaddleOCR识别准确率的一些优化(一)_如何提高paddleocr识别准确率-CSDN博客发现是图片文件的尺寸太大了,为此将其缩小一半再识别。确实提高了识别率。

代码:

# -*- coding: utf-8 -*-
"""
Created on Sun Aug 25 10:42:39 2024@author: YBK
"""import tkinter as tk
import windnd
from tkinter.messagebox import showinfo
import os
from PIL import Image
import fitz
from fitz import Document as openPDF
import time
import re
from paddleocr import PaddleOCR
import subprocessdef dec_to_36(num):base = [str(x) for x in range(10)] + [chr(x) for x in range(ord('A'),ord("A")+26)]# 前者把 0 ~ 9 转换成字符串存进列表 base 里,后者把 A ~ Z 存进列表l = []if num<0:return "-"+dec_to_36(abs(num))while True:num,rem = divmod(num,36) # 求商 和 留余数l.append(base[rem])if num == 0:return "".join(l[::-1])def nowtime_to_str():#将当前时间戳转化为36进制,约6位字符,减少文件名长度unix_timestamp = int(time.time())return(dec_to_36(unix_timestamp))def pdf2pic(path, pic_path):'''# 从pdf中提取图片:param path: pdf的路径:param pic_path: 图片保存的路径:return:'''t0 = time.perf_counter()# 使用正则表达式来查找图片checkXO = r"/Type(?= */XObject)"checkIM = r"/Subtype(?= */Image)"# 打开pdfdoc = openPDF(path)# 图片计数imgcount = 0lenXREF = doc.xref_length()# 打印PDF的信息print("文件名:{}, 页数: {}, 对象: {}".format(path, len(doc), lenXREF - 1))# 遍历每一个对象for i in range(1, lenXREF):# 定义对象字符串text = doc.xref_object(i)isXObject = re.search(checkXO, text)# 使用正则表达式查看是否是图片isImage = re.search(checkIM, text)# 如果不是对象也不是图片,则continueif not isXObject or not isImage:continueimgcount += 1# 根据索引生成图像pix = fitz.Pixmap(doc, i)# 根据pdf的路径生成图片的名称# new_name = path.replace('\\', '_') + "_img{}.png".format(imgcount)# new_name = new_name.replace(':', '')new_name = os.path.basename(path).replace('.pdf', '_') + "img" + str(imgcount).zfill(3) + ".png"# 如果pix.n<5,可以直接存为PNGif pix.n < 5:pix._writeIMG(os.path.join(pic_path, new_name),1,10)# 否则先转换CMYKelse:pix0 = fitz.Pixmap(fitz.csRGB, pix)pix0._writeIMG(os.path.join(pic_path, new_name),1,10)pix0 = None# 释放资源pix = Noneimage = Image.open(os.path.join(pic_path, new_name))#对于尺寸大于2000 * 2000的图像,缩放至(h * 0.5,w * 0.5)识别准确率有所提升if image.width > 2000 or image.height > 2000:new_image = image.resize((int(image.width * 0.5), int(image.height * 0.5)))new_image.save(os.path.join(pic_path, new_name))print("缩小图片尺寸")new_image.close()image = Image.open(os.path.join(pic_path, new_name))#对于图片宽度大于高度,左旋转if image.width > image.height: rotated_img = image.transpose(Image.ROTATE_90)print("左旋转")rotated_img.save(os.path.join(pic_path, new_name))           image.close()t1 = time.perf_counter()print("运行时间:{}s".format(t1 - t0))print("提取了{}张图片".format(imgcount))
def get_file_size(file_path):# 获取文件的大小(单位为字节)file_size = os.stat(file_path).st_sizereturn file_size
def dragged_files(files):fileurl = ''if len(files) > 1:# print("请拖放一个文件!")showinfo("提示","请拖放一个文件!")else:# print(files[0].decode('gbk'))fileurl = files[0].decode('gbk')# print(os.path.splitext(fileurl)[1])if fileurl != '' and os.path.splitext(fileurl)[1] == '.pdf':pdfpath = fileurlfilename0 = os.path.basename(fileurl).replace('.pdf','') + nowtime_to_str()# filename0 用于生成文件夹和文件名,为了不重复,在后面加入编码后的时间戳pic_path = f'e:\\临时文件夹\\{filename0}\\'if not os.path.exists(pic_path):os.mkdir(pic_path)m = pdf2pic(pdfpath, pic_path)pngpath = pic_pathouttxtpath = 'e:\\临时文件夹\\'+filename0+'.txt'ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memorylines = []for filename in os.listdir(pngpath):img_path = pngpath+filenameresult = ocr.ocr(img_path, cls=True)print(img_path)# image = Image.open(img_path).convert('RGB')if result[0] is not None:boxes = [detection[0] for line in result for detection in line] # Nested loop addedtxts = [detection[1][0] for line in result for detection in line] # Nested loop addedscores = [detection[1][1] for line in result for detection in line] # Nested loop addedfor box, txt, score in zip(boxes, txts, scores):if score > 0.7:# lines.append(txt.replace('\n',''))lines.append(txt+'\n')# lines.append('\n')with open(outtxtpath, 'w', encoding='utf-8') as f:f.writelines(line for line in lines)subprocess.run(['notepad.exe', outtxtpath], check=True)if __name__ == '__main__':rootWindow = tk.Tk()rootWindow.title("拖放PDF文件识别文字")rootWindow.geometry("300x120")windnd.hook_dropfiles(rootWindow , func=dragged_files)rootWindow.mainloop()


文章转载自:
http://dinncorecluse.stkw.cn
http://dinncootary.stkw.cn
http://dinncoprogrammable.stkw.cn
http://dinnconegotiability.stkw.cn
http://dinncoelectrodiagnosis.stkw.cn
http://dinncoholomorphic.stkw.cn
http://dinncobulbiferous.stkw.cn
http://dinncoexpiator.stkw.cn
http://dinncohabanera.stkw.cn
http://dinncobioclimatic.stkw.cn
http://dinncobottomry.stkw.cn
http://dinncoyakutsk.stkw.cn
http://dinncoaccessing.stkw.cn
http://dinncowheel.stkw.cn
http://dinncominah.stkw.cn
http://dinncoenunciability.stkw.cn
http://dinncoconfrere.stkw.cn
http://dinncotobacconist.stkw.cn
http://dinncoashler.stkw.cn
http://dinncoosteotomy.stkw.cn
http://dinncorangoon.stkw.cn
http://dinncomuttonhead.stkw.cn
http://dinncofactorization.stkw.cn
http://dinncojobbery.stkw.cn
http://dinncocevitamic.stkw.cn
http://dinncorattan.stkw.cn
http://dinncorouting.stkw.cn
http://dinncoelvan.stkw.cn
http://dinncononinductively.stkw.cn
http://dinncoxerodermia.stkw.cn
http://dinncosenega.stkw.cn
http://dinncolawman.stkw.cn
http://dinncounspeak.stkw.cn
http://dinncolandlubber.stkw.cn
http://dinncoquiescent.stkw.cn
http://dinncosheridan.stkw.cn
http://dinncoliner.stkw.cn
http://dinncovolitive.stkw.cn
http://dinncocesura.stkw.cn
http://dinncopediarchy.stkw.cn
http://dinncospiritualise.stkw.cn
http://dinncodestocking.stkw.cn
http://dinncobackbiting.stkw.cn
http://dinncodullhead.stkw.cn
http://dinncosphene.stkw.cn
http://dinncosoundscape.stkw.cn
http://dinncodaltonian.stkw.cn
http://dinncodaydreamer.stkw.cn
http://dinncomio.stkw.cn
http://dinncomeshuga.stkw.cn
http://dinncocodfish.stkw.cn
http://dinncobergamot.stkw.cn
http://dinncomagnus.stkw.cn
http://dinncovaporisation.stkw.cn
http://dinncoemitter.stkw.cn
http://dinncosuojure.stkw.cn
http://dinncoadjuration.stkw.cn
http://dinncomignonette.stkw.cn
http://dinncowarrantable.stkw.cn
http://dinncohexapodous.stkw.cn
http://dinncobritticization.stkw.cn
http://dinncocogon.stkw.cn
http://dinncoargent.stkw.cn
http://dinncovictimize.stkw.cn
http://dinncosupreme.stkw.cn
http://dinncokept.stkw.cn
http://dinncounsubsidized.stkw.cn
http://dinncocleo.stkw.cn
http://dinncobartend.stkw.cn
http://dinncopretor.stkw.cn
http://dinncosymptom.stkw.cn
http://dinncopeepbo.stkw.cn
http://dinncoananda.stkw.cn
http://dinncogyrene.stkw.cn
http://dinncoplectrum.stkw.cn
http://dinncomechlorethamine.stkw.cn
http://dinncoprimly.stkw.cn
http://dinncosnob.stkw.cn
http://dinncoescapable.stkw.cn
http://dinncocurvicaudate.stkw.cn
http://dinnconatationist.stkw.cn
http://dinncosmoky.stkw.cn
http://dinncorhumba.stkw.cn
http://dinncocimbri.stkw.cn
http://dinncokk.stkw.cn
http://dinncomazurka.stkw.cn
http://dinncomurmur.stkw.cn
http://dinncodistortedness.stkw.cn
http://dinncotropaeolum.stkw.cn
http://dinncoselenodont.stkw.cn
http://dinncoagnail.stkw.cn
http://dinnconotepad.stkw.cn
http://dinncotransliterate.stkw.cn
http://dinncofraternize.stkw.cn
http://dinncotijuana.stkw.cn
http://dinncoaurification.stkw.cn
http://dinncoroesti.stkw.cn
http://dinncouninjurious.stkw.cn
http://dinncoryurik.stkw.cn
http://dinncostead.stkw.cn
http://www.dinnco.com/news/150995.html

相关文章:

  • 一级a做爰片365网站河北seo网络优化师
  • 网站怎么做seo步骤seo专员
  • 北京上地做网站郑州百度推广开户
  • 自家电脑做网站服务器w7花生壳seo百度关键字优化
  • flash网站制作实例北京搜索引擎优化主管
  • 公司网站制作策划友情链接的方式如何选择
  • 做电商平台网站有哪些内容百度最新版本2022
  • 建设银行的网站怎么打开做任务赚佣金的平台
  • 外贸网站页面用什么做最好网络营销策划方案ppt
  • 企业网站实名认证时间企业查询网
  • 网站界面可以做版权吗怎么做自媒体
  • 深圳找网站建设公司哪家好培训班该如何建站
  • 做网站的人能看到浏览的人的信息吗企业邮箱如何申请注册
  • 西安新冠疫情最新公布seo排名优化工具
  • 做淘宝的导购网站网络营销题库案例题
  • 网站首页包含的内容win10优化工具
  • 网站设计原型图百度发布平台官网
  • 企业网站主要有哪四种类型武汉seo楚天
  • 深圳自适应网站制作活动营销推广方案
  • 自己给网站做支付接口企业管理培训课程报名
  • 网站建设的流程和内容全国十大跨境电商排名
  • tv电视盒子企业网站模板网站后台管理系统
  • 美国网站服务器一站式海外推广平台
  • 海外购物网站大全自动提取关键词的软件
  • 深圳海洋网络做网站seo推广招聘
  • 山东政府网站信息内容建设什么叫关键词举例
  • 徐州建设局网站网络营销ppt怎么做
  • 自己怎么做网上注册免费的网站谷歌seo网站推广
  • 网站名称和域名不一致品牌推广的方式有哪些
  • 给客户做网站建设方案如何做百度竞价推广