Skip to content

Commit

Permalink
更新文字识别的模块
Browse files Browse the repository at this point in the history
  • Loading branch information
duolabmeng6 committed Feb 18, 2023
1 parent 4ddc0a3 commit e11fecc
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pyefun/人工智能/通用文字识别.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e11fecc

Please sign in to comment.