Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Add kwargs

SWHL066d17645e13
diff --git a/python/demo.py b/python/demo.py
index f964558..55b4bbc 100644
--- a/python/demo.py
+++ b/python/demo.py
@@ -90,7 +90,7 @@ def visualize(image_path, result, font_path="resources/fonts/FZYTK.TTF"):
if __name__ == '__main__':
text_sys = RapidOCR()
- image_path = '1.png'
+ image_path = 'test_images/ch_en_num.jpg'
img = cv2.imread(image_path)
result, elapse_list = text_sys(img)
print(result)
diff --git a/python/rapidocr_onnxruntime/rapid_ocr_api.py b/python/rapidocr_onnxruntime/rapid_ocr_api.py
index 6d92822..cb5680d 100644
--- a/python/rapidocr_onnxruntime/rapid_ocr_api.py
+++ b/python/rapidocr_onnxruntime/rapid_ocr_api.py
@@ -44,7 +44,18 @@ class RapidOCR():
config['Cls']['class_name'])
self.text_cls = TextClassifier(config['Cls'])
- def __call__(self, img: np.ndarray):
+ def __call__(self, img: np.ndarray, **kwargs):
+ if kwargs:
+ # 获得超参数
+ box_thresh = kwargs.get('box_thresh', 0.5)
+ unclip_ratio = kwargs.get('unclip_ratio', 1.6)
+ text_score = kwargs.get('text_score', 0.5)
+
+ # 更新超参数
+ self.text_detector.postprocess_op.box_thresh = box_thresh
+ self.text_detector.postprocess_op.unclip_ratio = unclip_ratio
+ self.text_score = text_score
+
h, w = img.shape[:2]
if self.width_height_ratio == -1:
use_limit_ratio = False
diff --git a/python/rapidocr_openvino/rapid_ocr_api.py b/python/rapidocr_openvino/rapid_ocr_api.py
index 6d92822..cb5680d 100644
--- a/python/rapidocr_openvino/rapid_ocr_api.py
+++ b/python/rapidocr_openvino/rapid_ocr_api.py
@@ -44,7 +44,18 @@ class RapidOCR():
config['Cls']['class_name'])
self.text_cls = TextClassifier(config['Cls'])
- def __call__(self, img: np.ndarray):
+ def __call__(self, img: np.ndarray, **kwargs):
+ if kwargs:
+ # 获得超参数
+ box_thresh = kwargs.get('box_thresh', 0.5)
+ unclip_ratio = kwargs.get('unclip_ratio', 1.6)
+ text_score = kwargs.get('text_score', 0.5)
+
+ # 更新超参数
+ self.text_detector.postprocess_op.box_thresh = box_thresh
+ self.text_detector.postprocess_op.unclip_ratio = unclip_ratio
+ self.text_score = text_score
+
h, w = img.shape[:2]
if self.width_height_ratio == -1:
use_limit_ratio = False