Metade的OCR神器nougat强出了天际,赶紧试用一番!

文章目录

摘要

https://arxiv.org/pdf/2308.13418.pdf
https://github.com/facebookresearch/nougat

nougat:你们能识别的,我可以识别,你们不能识别的,我也可以识别,Meta出品,大厂背景!这就是nougat!!!

切页

试用了一番nougat,很强!很牛!但是也很耗显存,为了省显存,只能先做点处理,首先将PDF文档转成一页一页的,代码如下:

"""
	用途:将一个 PDF 文件按页拆分为多个 PDF 文件

    注意事项:若报错 ModuleNotFoundError: No module named 'PyPDF2'
             则需要先安装该模块。使用命令 “pip install PyPDF2” 安装即可
"""


import PyPDF2  # 需要先安装:pip/pip3 install PyPDF2
import os

# root = r'C:\Users\liujieru\Documents\pdf'  # 源文件所在的绝对路径
# file_path = os.path.join(root, '组合.pdf')
file_path='2308.13418.pdf'
pdf_file = open(file_path, 'rb')  # 获取原 PDF 文件
pdf_reader = PyPDF2.PdfReader(pdf_file)  # 创建 PDF 对象
source_name = pdf_file.name  # 获取源文件名称,包含绝对路径

pdf_writer = PyPDF2.PdfWriter()  # 创建一个空白 PDF 对象

for page_num in range(len(pdf_reader.pages)):  # 将每页内容分别写入一个新文件
    page_obj =pdf_reader.pages[page_num]# pdf_reader.getPage(page_num)
    pdf_writer.add_page(page_obj)  # 向空白 PDF 对象中添加要复制的 PDF页面

    new_name = source_name[:-4] + str(page_num) + ".pdf"
    pdf_new_file = open(new_name, 'wb')  # 创建一个新文件
    pdf_writer.write(pdf_new_file)  # 将添加了内容的空白 PDF 对象,写入到新建文件中
    pdf_new_file.close()

    pdf_writer.__init__()  # 将 PDF 对象初始化

pdf_file.close()

PDF就用论文了!

转成之后,我们就开始安装nougat,

安装

From pip:

pip install nougat-ocr

From repository:

pip install git+https://github.com/facebookresearch/nougat

There are extra dependencies if you want to call the model from an API or generate a dataset.
Install via

pip install "nougat-ocr[api]" or pip install "nougat-ocr[dataset]"

好吧!主打的就是简单!!!

运行

这个就更简单了!

nougat path/to/file.pdf

我将PDF已经切成一页一页的,然后,我们测试第一页!

nougat 2308.134180.pdf

在这里插入图片描述

如果你想保存成文件,可以增加输出的路径!

nougat 2308.134181.pdf --out out

在这里插入图片描述
打开看看效果如何?

在这里插入图片描述
Mete最近有疯狂,疯狂的开源!

猜你喜欢

转载自blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/132588428