From e11fecc2ddde37842d79037e39ffbc4a3a89baca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C1715109585=E2=80=9D?= <1715109585@qq.com> Date: Sat, 18 Feb 2023 23:56:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E5=AD=97=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E7=9A=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...07\345\255\227\350\257\206\345\210\253.py" | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git "a/pyefun/\344\272\272\345\267\245\346\231\272\350\203\275/\351\200\232\347\224\250\346\226\207\345\255\227\350\257\206\345\210\253.py" "b/pyefun/\344\272\272\345\267\245\346\231\272\350\203\275/\351\200\232\347\224\250\346\226\207\345\255\227\350\257\206\345\210\253.py" index 44ec035..0eb7fda 100644 --- "a/pyefun/\344\272\272\345\267\245\346\231\272\350\203\275/\351\200\232\347\224\250\346\226\207\345\255\227\350\257\206\345\210\253.py" +++ "b/pyefun/\344\272\272\345\267\245\346\231\272\350\203\275/\351\200\232\347\224\250\346\226\207\345\255\227\350\257\206\345\210\253.py" @@ -1,22 +1,35 @@ """ -需要安装 ppppocr 的库 -pip install ppppocr +需要安装 rapidocr 的库 +pip install rapidocr-onnxruntime """ -import ppppocr - -ocr = ppppocr.ppppOcr() def 通用文字识别(图片路径): - dt_boxes, rec_res = ocr.ocr(图片路径) - return dt_boxes, rec_res + rapid_ocr = RapidOCR() + return result def 通用文字识别获取文字(图片路径): - dt_boxes, rec_res = ocr.ocr(图片路径) - return ocr.toText(rec_res) + rapid_ocr = RapidOCR() + result = rapid_ocr(图片路径) + results = [] + for i, (rec, text, score) in enumerate(result[0]): + results.append(text) + print(text) + return " ".join(results) def 通用文字识别获取Json(图片路径): - dt_boxes, rec_res = ocr.ocr(图片路径) - return ocr.toJson(dt_boxes, rec_res) + rapid_ocr = RapidOCR() + result = rapid_ocr(图片路径) + results = [] + for i, (dt_boxes, text, score) in enumerate(result[0]): + results.append(text) + print(text) + boxs = [(int(v[0]), int(v[1])) for v in dt_boxes] + results.append({ + "text_box_position": boxs, + "text": text, + "confidence": str(score), + }) + return results \ No newline at end of file