您的位置:首页 > 新闻 > 热点要闻 > 重庆seo整站优化系统_网页界面设计中_外链网盘下载_免费海报模板网站

重庆seo整站优化系统_网页界面设计中_外链网盘下载_免费海报模板网站

2026/2/21 5:20:30 来源:https://blog.csdn.net/qq_41709084/article/details/143574356  浏览:    关键词:重庆seo整站优化系统_网页界面设计中_外链网盘下载_免费海报模板网站
重庆seo整站优化系统_网页界面设计中_外链网盘下载_免费海报模板网站
#识别图片
pip3 install paddleocr
pip3 install paddlepaddle#识别pdf
pip3 install PyMuPDF

 重点:路径不能有中文,不然pdf文件访问不了

from paddleocr import PaddleOCR
from rest_framework.response import Response
from rest_framework.views import APIView# 识别单张图片
class GetOneImage(APIView):def get(self, request, *args, **kwargs):ocr = PaddleOCR(use_angle_cls=True, lang="ch")  # need to run only once to download and load model into memoryimg_path = 'F:/OCR/data/4.png'result = ocr.ocr(img_path, cls=True)for idx in range(len(result)):res = result[idx]for line in res:print(line)# 显示结果for idx in range(len(result)):res = result[idx]txts = [line[1][0] for line in res]return Response({'code': 200, "data": txts})import datetime
import fitz  # fitz就是pip install PyMuPDF
import os
import cv2
from paddleocr import PPStructure
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes# 中文测试图
table_engine = PPStructure(recovery=True, lang='ch')#识别pdf
class GetPDF(APIView):def get(self, request, *args, **kwargs):pdfPath = "F:/OCR/image/13.pdf";imagePath = "F:/OCR/image/13"startTime_pdf2img = datetime.datetime.now()  # 开始时间print("imagePath=" + imagePath)if not os.path.exists(imagePath):os.makedirs(imagePath)pdfDoc = fitz.open(pdfPath)totalPage = pdfDoc.page_countfor pg in range(totalPage):page = pdfDoc[pg]rotate = int(0)zoom_x = 2zoom_y = 2mat = fitz.Matrix(zoom_x, zoom_y).prerotate(rotate)pix = page.get_pixmap(matrix=mat, alpha=False)print(f'正在保存{pdfPath}的第{pg + 1}页,共{totalPage}页')pix.save(imagePath + '/' + f'images_{pg + 1}.png')endTime_pdf2img = datetime.datetime.now()print(f'{pdfDoc}-pdf2img-花费时间={(endTime_pdf2img - startTime_pdf2img).seconds}秒')img_path = imagePath;text = []imgs = os.listdir(img_path)for img_name in imgs:img = cv2.imread(os.path.join(img_path, img_name))result = table_engine(img)h, w, _ = img.shaperes = sorted_layout_boxes(result, w)for line in res:line.pop('img')print(line)for pra in line['res']:text.append(pra['text'])text.append('\n')return Response({'code': 200, "data": text})

参考:使用paddleOCR批量识别pdf_paddleocr pdf-CSDN博客

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com