-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ddc0a3
commit e11fecc
Showing
1 changed file
with
24 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |