fix(rapidocr): complete parsing parameters

This commit is contained in:
SWHL committed 2025-03-09 10:06:04 +08:00
1 parent 6b79d0cfbe
commit 2a420e013e
7 files changed
+102 -131

No files matched your search

+1 -15
View File
@@ -5,27 +5,13 @@ import cv2
from rapidocr import RapidOCR, VisRes
# from rapidocr_onnxruntime import RapidOCR, VisRes
# from rapidocr_torch import RapidOCR, VisRes
# from rapidocr_paddle import RapidOCR, VisRes
# from rapidocr_openvino import RapidOCR, VisRes
# yaml_path = "tests/test_files/config.yaml"
# engine = RapidOCR(config_path=yaml_path)
# engine = engine = RapidOCR(
# params={"Global.with_onnx": True, "EngineConfig.onnxruntime.use_cuda": True}
# )
# engine = RapidOCR(params={"Global.with_torch": True, "Global.lang": "ch"})
engine = RapidOCR(params={"Global.with_openvino": True, "Global.lang_rec": "ch_server"})
engine = RapidOCR(params={"Global.with_openvino": True})
vis = VisRes()
image_path = "tests/test_files/ch_en_num.jpg"
with open(image_path, "rb") as f:
img = f.read()
# result, elapse_list = engine(img, use_det=True, use_cls=False, use_rec=False)
result = engine(img, return_word_box=True)
print(result)
print(result.elapse)
+2 -2
View File
@@ -351,12 +351,12 @@ def main(arg_list: Optional[List[str]] = None):
vis_img = vis(args.img_path, words_boxes, words, words_scores)
save_path = cur_dir / f"{Path(args.img_path).stem}_vis_single.png"
cv2.imwrite(str(save_path), vis_img)
print("The vis single result has saved in %s", save_path)
print(f"The vis single result has saved in {save_path}")
else:
save_path = cur_dir / f"{Path(args.img_path).stem}_vis.png"
vis_img = vis(args.img_path, result.boxes, result.txts, result.scores)
cv2.imwrite(str(save_path), vis_img)
print("The vis result has saved in %s", save_path)
print(f"The vis result has saved in {save_path}")
if __name__ == "__main__":
+4 -103
View File
@@ -122,119 +122,20 @@ class ParseLang:
return "devanagari"
if lang in ["ch", "en"]:
return
pass
raise ValueError(f"lang: {lang} is not in the supported list.")
def parse_lang(lang):
latin_lang = [
"af",
"az",
"bs",
"cs",
"cy",
"da",
"de",
"es",
"et",
"fr",
"ga",
"hr",
"hu",
"id",
"is",
"it",
"ku",
"la",
"lt",
"lv",
"mi",
"ms",
"mt",
"nl",
"no",
"oc",
"pi",
"pl",
"pt",
"ro",
"rs_latin",
"sk",
"sl",
"sq",
"sv",
"sw",
"tl",
"tr",
"uz",
"vi",
"french",
"german",
]
arabic_lang = ["ar", "fa", "ug", "ur"]
cyrillic_lang = [
"ru",
"rs_cyrillic",
"be",
"bg",
"uk",
"mn",
"abq",
"ady",
"kbd",
"ava",
"dar",
"inh",
"che",
"lbe",
"lez",
"tab",
]
devanagari_lang = [
"hi",
"mr",
"ne",
"bh",
"mai",
"ang",
"bho",
"mah",
"sck",
"new",
"gom",
"sa",
"bgc",
]
if lang in latin_lang:
lang = "latin"
elif lang in arabic_lang:
lang = "arabic"
elif lang in cyrillic_lang:
lang = "cyrillic"
elif lang in devanagari_lang:
lang = "devanagari"
elif lang in ["ch", "en"]:
pass
else:
raise ValueError(f"lang: {lang} is not in the supported list.")
if lang == "ch":
det_lang = "ch"
elif lang in ["en", "latin"]:
det_lang = "en"
else:
det_lang = "Multilingual"
return det_lang, lang
class ParseParams(OmegaConf):
def __init__(self):
pass
@classmethod
def update_batch(cls, cfg: DictConfig, params: Dict[str, str]) -> DictConfig:
global_keys = list(OmegaConf.to_container(cfg.Global).keys())
for k, v in params.items():
if k.startswith("Global") and k.split(".")[1] not in global_keys:
raise ValueError(f"{k} is not a valid key.")
cls.update(cfg, k, v)
return cfg
+2 -1
View File
@@ -6,4 +6,5 @@ Shapely>=1.7.1,!=2.0.4 # python3.12 2.0.4 bug
PyYAML
Pillow
onnxruntime>=1.7.0
tqdm
tqdm
omegaconf
+2 -2
View File
@@ -79,11 +79,11 @@ def test_error_lang():
def test_lang():
engine = get_engine(params={"Global.lang": "en"})
engine = get_engine(params={"Global.lang_rec": "en_mobile"})
img_path = tests_dir / "en.jpg"
result = engine(img_path)
assert result.txts is not None
assert result.txts[0] == "MovieShots Dataset"
assert result.txts[0] == "3"
def test_engine_openvino():