您现在的位置是:热点 >>正文
告别「复制+粘贴」,基于深度学习的OCR,实现PDF转文本
热点3829人已围观
简介...
传统的讲座通常伴随着一组 pdf 幻灯片。一般来说,想要对此类讲座做笔记,需要从 pdf 复制、粘贴很多内容。
最近,来自 K1 Digital 的高级机器学习工程师 Lucas Soares 一直在尝试通过使用 OCR(光学字符识别)自动转录 pdf 幻灯片,以便直接在 markdown 文件中操作它们的内容,从而避免手动复制和粘贴 pdf 内容,实现这一过程的自动化。
左为项目作者 Lucas Soares。
项目地址:https://github.com/EnkrateiaLucca/ocr_for_transcribing_pdf_slides
为什么不使用传统的 pdf 转文本工具呢?
Lucas Soares 发现传统工具往往会带来更多的问题,需要告别花时间解决。他曾经尝试使用传统的 Python 软件包,但是遇到了很多问题(例如必须使用复杂的正则表达式模式解析最终输出等),因此决定尝试使用目标检测和 OCR 来解决。
基本过程可分为以下步骤:
将 pdf 转换为图片; 检测和识别图像中的文本; 展示示例输出。
基于深度学习的 OCR 将 pdf 转录为文本
将 pdf 转换为图像
Soares 使用的 pdf 幻灯片来自于 David Silver 的增强学习(参见以下 pdf 幻灯片地址)。使用「pdf2image」包将每张幻灯片转换为 png 图像格式。
pdf 幻灯片示例。
地址:https://www.davidsilver.uk/wp-content/uploads/2020/03/intro「复_RL.pdf
代码如下:
from pdf2image import convert_from_path from pdf2image.exceptions import ( PDFInfoNotInstalledError, PDFPageCountError, PDFSyntaxError ) pdf_path = "path/to/file/intro_RL_Lecture1.pdf" images制+ = convert_from_path(pdf_path) for i, image in enumerate(images): fname = "image" + str(i) + ".png" image.save(fname, "PNG")
经过处理后,所有的 pdf 幻灯片都转换成 png 格式的图像:
检测和识别图像中的文本
为了检测和识别 png粘贴 图像中的文本,Soares 使用 ocr.pytorch 库中的文本检测器。按照说明下载模型并将模型保存在 checkpoints 文件夹中。
ocr.pytorch 库地址:https://github.com/courao/ocr.pytorch
代码如下:
# adapted from this source: https://github.com/courao/ocr.pytorch %load_ext autoreload %autoreload 2 import os from o」,cr import ocr import time import shutil import numpy as np import pathlib from PIL import Image from glob import glob import matplotlib.pyplot as plt import seaborn as 基于sns sns.set() import pytesseract def single_pic_proc(image_file): image = np.array(Image.open(image_file).convert('RGB')) result, image_framed = ocr(image) return 深度result,image_framed image_files = glob('./input_images/*.*') result_dir = './output_images_with_boxes/' # If the output folder exists we will remove it and redo it. if os.path.exists(result_d学习ir): shutil.rmtree(result_dir) os.mkdir(result_dir) for image_file in sorted(image_files): result, image_framed = single_pic_proc(image_file) # detecting and recognizing the te的Oxt filename = pathlib.Path(image_file).name output_file = os.path.join(result_dir, image_file.split('/')[-1]) txt_file = os.path.join(result_dir, image_file.split('/')[-1].split('CR.')[0]+'.txt') txt_f = open(txt_file, 'w') Image.fromarray(image_framed).save(output_file) for key in result: txt_f.write(result[key][1]+,实' ') txt_f.close()
设置输入和输出文件夹,接着遍历所有输入图像(转换后的 pdf 幻灯片),然后通过 single_pic_proc() 函数运行 OCR 模块中的检测和识别模型,最后将输出保存到输出文件夹。
其中检测继承(inherit)了 Pytorch CTPN 模型,识别继承了 Pytorch CRNN 模型,两者都存在于 OCR 模块中。
示例输出
代码如下:
import cv2 as cv output_dir = pathlib.Path("./output_im现Pages_with_boxes") # image = cv.imread(str(np.random.choice(list(output_dir.iterdir()),1)[0])) image = cv.imread(f"{output_dir}/image7.png") size_reshaped = (int(image.shape[1]),int(image.shape[0])) image = cv.resize(image, sizDFe_reshaped) cv.imshow("image", image) cv.waitKey(0) cv.destroyAllWindows()
下图左为原始 pdf 幻灯片,图右为转录后的输出文本,转录后的准确率非常高。
文本识别输出如下:
filename = f"{output_dir}/image7.txt" with open(filename, "r") as text: for line&nbs转文p;in text.readlines(): print(line.strip(" "))
通过上述方法,最终你可以得到一个非常强大的工具来转录各种文档,从检测和识别手写笔记到检测和识别照片中的随机文本。拥有自己的 OCR 工具来处理一些文本内容,这比依赖外部软件来转录文档要好的多。
Tags:
相关文章
苹果史上最大胆合作!Claude Sonnet 4强势入驻Xcode,3400万开发者集体沸腾
热点科技界刚刚发生了一件震撼性事件!苹果这家向来以封闭生态著称的科技巨头,竟然主动拥抱外部AI力量,与Anthropic达成重磅合作,将Claude Sonnet4直接植入Xcode26Beta7的心脏。...
【热点】
阅读更多Adobe王炸更新:Firefly智能体公测,Photoshop竟能“自如编排”?
热点Adobe公司于 4 月 28 日正式宣布,其备受期待的Firefly AI Assistant(Firefly AI助手)正式进入公测阶段,并开始向全球符合条件的订阅用户开放。首批体验名单涵盖了Cr...
【热点】
阅读更多标签: 中国移动 Token办公室 词元套餐 AlibabaTokenHub
热点云梦级6月30日云梦级消息,据报道,中国移动于近日正式设立 Token 办公室,该部门为集团级战略机构,级别高于此前成立的算力办公室,由集团核心领导直接挂帅督战,战略发展部总经理出任 Token 办公...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=外推留痕软件【tg:seogoogle987】,VSp
- https://www.wou.edu.my/?s=外推留痕软件【tg:seogoogle987】,Nro
- https://www.merchbar.com/search?q=外推留痕软件【tg:seogoogle987】,arC
- https://xn--lgernevedlystskoven-lxb.dk/search/外推留痕软件【tg:seogoogle987】,6yg
- https://www.paxnet.co.kr/search/jongmok?kwd=外推留痕软件【tg:seogoogle987】LVi
- https://www.roberthalf.com/us/en/jobs/all/外推留痕软件【tg:seogoogle987】sOO
- https://www.teacherspayteachers.com/Browse/Search:外推留痕软件【tg:seogoogle987】,puX
- https://www.youtube.com/hashtag/外推留痕软件【tg:seogoogle987】,viC
- https://www.kaskus.co.id/search?q=外推留痕软件【tg:seogoogle987】,mMG
- https://www.selfsufficientish.com/main/?s=外推留痕软件【tg:seogoogle987】,j7h
- https://www.sbaad.no/search/外推留痕软件【tg:seogoogle987】,1fN
- https://www.navylookout.com/?ID=nSBR6Ivdu6lZg1yr2SDs30Lo5sTs76yJ&s=外推留痕软件【tg:seogoogle987】,VuP
- https://www.skicheck.at/en/?action=CHECK&s=外推留痕软件【tg:seogoogle987】,iHK
- https://search.danawa.com/dsearch.php?query=外推留痕软件【tg:seogoogle987】K8a
- https://www.lifesciencesweden.se/search?q=外推留痕软件【tg:seogoogle987】,mBL
- https://hsmoa.com/search?query=外推留痕软件【tg:seogoogle987】bU1
- https://www.voices.com/talents/search?keywords=外推留痕软件【tg:seogoogle987】,Wd3
- https://www.tarleton.edu/?s=外推留痕软件【tg:seogoogle987】,KnN
- https://www.kawainter.com/catalogsearch/result/?q=外推留痕软件【tg:seogoogle987】,NaB
- https://www.rollingstone.it/?ID=DVMeu3AlmzZE1cuJ2FmgmO5TSCQRb3yh&s=外推留痕软件【tg:seogoogle987】,LIp
- https://www.tiktok.com/tag/外推留痕软件【tg:seogoogle987】,wrt
- https://www.teamlab.art/ko/?submit=外推留痕软件【tg:seogoogle987】,LbD
- https://store.line.me/search/sticker/ja?q=外推留痕软件【tg:seogoogle987】cFW
- https://www.teamlab.art/it/?submit=外推留痕软件【tg:seogoogle987】,lkJ
- https://www.manga-news.com/index.php/recherche/?q=外推留痕软件【tg:seogoogle987】,bbi
- https://www.lneg.pt/?cat=140&s=外推留痕软件【tg:seogoogle987】,k2E
- https://www.jusoen.com/addreng.asp?p1=外推留痕软件【tg:seogoogle987】2wD
- https://www.parriscues.com/catalogsearch/result/?q=外推留痕软件【tg:seogoogle987】,nCe
- https://www.kuaikanmanhua.com/sou/外推留痕软件【tg:seogoogle987】,wo7
- https://wwwcp.umes.edu/search/外推留痕软件【tg:seogoogle987】,JIU
- https://www.polliwogs.com/search/外推留痕软件【tg:seogoogle987】,XjP
- https://www.youtube.com/results?search_query=外推留痕软件【tg:seogoogle987】,VPr
- https://www.ng-slo.si/si/iskanje?cat=114&q=外推留痕软件【tg:seogoogle987】,4Qu
- https://www.wattpad.com/search/外推留痕软件【tg:seogoogle987】Rmi
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=外推留痕软件【tg:seogoogle987】R8w
- https://www.quarterjacksurgery.co.uk/?AT=3rBy&s=外推留痕软件【tg:seogoogle987】,Tys
- https://xehay.vn/tim-kiem/=外推留痕软件【tg:seogoogle987】,xaM
- https://www.sonepar.ch/fr/search?q=外推留痕软件【tg:seogoogle987】,iPl
- https://www.abbreviations.com/外推留痕软件【tg:seogoogle987】LK3
- https://www.valuecolleges.com/?action=QUERY&s=外推留痕软件【tg:seogoogle987】,fBT
- https://store.line.me/search/sticker/ja?q=外推留痕软件【tg:seogoogle987】YgY
- https://www.zalora.sg/catalog/?cat=112&q=外推留痕软件【tg:seogoogle987】,VTO
- https://www.temu.com/search_result.html?search_key=外推留痕软件【tg:seogoogle987】BwG
- https://www.lgnewsroom.com/search/外推留痕软件【tg:seogoogle987】,FHX
- https://www.rostaing.com/catalogsearch/result/?cat=22&q=外推留痕软件【tg:seogoogle987】,fBp
- https://www.routesonline.com/search/?query=外推留痕软件【tg:seogoogle987】,CqI
- https://www.swanagerailway.co.uk/search?q=外推留痕软件【tg:seogoogle987】,Opu
- https://www.pinkpanda.ro/magazin/ingrijirea-tenului?page=87&q=外推留痕软件【tg:seogoogle987】,LT3
- https://www.nctsn.org/search?cat=191&query=外推留痕软件【tg:seogoogle987】,iCC
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=外推留痕软件【tg:seogoogle987】,wIg