尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

paddleocr与EasyOCR初试体验

paddleocr与EasyOCR初试体验 paddleOCR和EasyOCR都是用于OCR技术的免费开源软件。paddleCOR是百度公司出品的EasyOCR是杰德公司JaidedAIEasyOCR的网址GitHub - JaidedAI/EasyOCRpaddleOCR的github仓库PaddlePaddle/PaddleOCRpaddleOCR的网站飞桨AI Studio星河社区-人工智能学习与实训社区总体来说paddleocr是OCR全家桶功能确实强又适应性广。但花在上面学习成本更高安装更繁琐。EasyOCR主打轻量级安装、上手都很快两行代码就能实现最基本的OCR效果但是缺陷也挺明显没有文本框架分析识别的字只言片语需要手动调整图片缩放比例另外虽然说说支持80多种语音但是不能简体中文俄语这样只能简体中文加英语或俄语英语否则会报错更别提俄语英语简体中文。选型推荐从应用场景来看想要一个demo或需要轻量级开源免费本地兜底就选EasyOCR。个人偶尔使用就选paddleocr在线解析它每天0点重置页数加入社区每天有20000页需要排队对项目有OCR识别程度有要求不怕识别时间稍长就选paddleOCR【注】Paddlepaddle相当于是paddleocr的引擎只安装paddleocr是运行不了的。避坑指南PaddleOCR的第一个坑就是PaddleOCR分为cpu版和gpu版。cpu版需要pytorch 、Paddlepaddle、paddleOCR[all]all是全部推理功能没有all是基础功能。默认Paddlepaddle是CPU版本的。我用的是pytorchCPU-only version 2.13.0cpupaddlepaddle是3.3.0。一直会报缺少shm.dll的错误这个shm.dll应该与oneDNN这个Inter加速库有关。一直没能彻底搞定这个问题。gpu版需要cuda、pytorch、paddlepaddle-gpu、paddleOCR[all]all是全部推理功能没有all是基础功能。这个下载依赖很慢需要找一个好的镜像我用的是阿里云的cuda12.4版本的镜像。下载好了以后也会遇到libiomp5md.dll依赖错误。因为paddlepaddle和pytorch都有这个镜像paddlepaddle的版本低pytorch的版本高先加载paddlepaddle时pytorch就不会再加载libiomp5md.dll。而先加载pytorch会兼容paddlepaddle的libiomp5md.dll也就不会报错。所以先import谁后import谁有说法的。PaddleOCR的第二个坑就是在线解析和本地解析的选择。我把EasyOCR的github上关于标牌的照片下载后用于PaddleOCR-v5和PaddleOCR-vl-1.6。其实本地的依赖gpu的paddleocr效果最好其次是PaddleOCR-vl-1.6最后是EasyOCR。PaddleOCR也有坑res[rec_texts]和res.rec_texts的写法支持上但是以前的有支持版本两者都支持也有支持其中一种的目前是仅支持前者。整体上图片能和文字大体上分开不会自动识别标题作者。识别的字精准率很高召回率一般。PaddleOCR-vl-1.6是个0.6B的轻量级视觉大模型在线试了下。响应速度很快1-2秒就有结果。但是也会漏字识别错字而且虽然免费但是要排队经常timeout。EasyOCR整体的效果而且是基于深度学习的。第一次使用要下载模型之外基本是最容易部署最方便的。上面的排队、依赖冲突、什么CPUGPU问题他都没有。它识别字体漏字效果差不认识版面结构。所以需要人手动去调整其他的参数才能达到可接受的效果尤其是面对大字问题。默认的图片放缩参数是mag_ratio1.5字体太大无法识别出来这是字。我选择的图片要调整到0.75才会有识别成功的效果如果调整到0.5又会因为精度不够知道这是字却识别错字。示例代码paddleOCRimport os import sys, io from paddleocr import PaddleOCR img_path rD:\work\PythonProject\R2.jpg ocr PaddleOCR( langch, use_textline_orientationTrue, use_doc_orientation_classifyFalse, # 关掉用不到的子模型也能少点日志 use_doc_unwarpingFalse, ) results list(ocr.predict(img_path)) print(f识别到 {len(results)} 个结果) value for i, res in enumerate(results): # print(f[{i}] {getattr(res, rec_texts, res)}) if rec_texts in res: value value.join(res[rec_texts]) print(value)EasyOCR EasyOCR import easyocr ocr easyocr.Reader([ch_sim,en],gpuTrue) result ocr.readtext(R2.png,detail0, mag_ratio0.75) # result ocr.readtext(R2.png,detail0) print(result)还有个官方的在线调用api的示例代码给你们粘贴过来import paddleocr # Please make sure the requests library is installed # pip install requests import json import os import requests import sys import time JOB_URL https://paddleocr.aistudio-app.com/api/v2/ocr/jobs TOKEN YOUR_TOKEN MODEL PaddleOCR-VL-1.6 file_path local file path or file url headers { Authorization: fbearer {TOKEN}, } optional_payload { useDocOrientationClassify: False, useDocUnwarping: False, useChartRecognition: False, } print(fProcessing file: {file_path}) if file_path.startswith(http): # URL Mode headers[Content-Type] application/json payload { fileUrl: file_path, model: MODEL, optionalPayload: optional_payload } job_response requests.post(JOB_URL, jsonpayload, headersheaders) else: # Local File Mode if not os.path.exists(file_path): print(fError: File not found at {file_path}) sys.exit(1) data { model: MODEL, optionalPayload: json.dumps(optional_payload) } with open(file_path, rb) as f: files {file: f} job_response requests.post(JOB_URL, headersheaders, datadata, filesfiles) print(fResponse status: {job_response.status_code}) if job_response.status_code ! 200: print(fResponse content: {job_response.text}) assert job_response.status_code 200 jobId job_response.json()[data][jobId] print(fJob submitted successfully. job id: {jobId}) print(Start polling for results) jsonl_url while True: job_result_response requests.get(f{JOB_URL}/{jobId}, headersheaders) assert job_result_response.status_code 200 state job_result_response.json()[data][state] if state pending: print(The current status of the job is pending) elif state running: try: total_pages job_result_response.json()[data][extractProgress][totalPages] extracted_pages job_result_response.json()[data][extractProgress][extractedPages] print( fThe current status of the job is running, total pages: {total_pages}, extracted pages: {extracted_pages}) except KeyError: print(The current status of the job is running...) elif state done: extracted_pages job_result_response.json()[data][extractProgress][extractedPages] start_time job_result_response.json()[data][extractProgress][startTime] end_time job_result_response.json()[data][extractProgress][endTime] print( fJob completed, successfully extracted pages: {extracted_pages}, start time: {start_time}, end time: {end_time}) jsonl_url job_result_response.json()[data][resultUrl][jsonUrl] break elif state failed: error_msg job_result_response.json()[data][errorMsg] print(fJob failed, failure reason{error_msg}) sys.exit() time.sleep(5) if jsonl_url: jsonl_response requests.get(jsonl_url) jsonl_response.raise_for_status() lines jsonl_response.text.strip().split(\n) output_dir output os.makedirs(output_dir, exist_okTrue) page_num 0 for line_num, line in enumerate(lines, start1): line line.strip() if not line: continue result json.loads(line)[result] for i, res in enumerate(result[layoutParsingResults]): md_filename os.path.join(output_dir, fdoc_{page_num}.md) with open(md_filename, w, encodingutf-8) as md_file: md_file.write(res[markdown][text]) print(fMarkdown document saved at {md_filename}) for img_path, img in res[markdown][images].items(): full_img_path os.path.join(output_dir, img_path) os.makedirs(os.path.dirname(full_img_path), exist_okTrue) img_bytes requests.get(img).content with open(full_img_path, wb) as img_file: img_file.write(img_bytes) print(fImage saved to: {full_img_path}) for img_name, img in res[outputImages].items(): img_response requests.get(img) if img_response.status_code 200: # Save image to local filename os.path.join(output_dir, f{img_name}_{page_num}.jpg) with open(filename, wb) as f: f.write(img_response.content) print(fImage saved to: {filename}) else: print(fFailed to download image, status code: {img_response.status_code}) page_num 1图片就不传了也不知道是不是视觉中国的图片。
返回列表