初始化

RapidOCR是主类,其初始化函数如下:

  class RapidOCR:
    def __init__(self, config_path: Optional[str] = None, **kwargs):
        pass
  

支持两种自定义传参数的方案,下面分别详细说明:

  • config.yaml方式

    1. 找到rapidocr_onnxruntime安装目录下的config.yaml文件,可以通过pip show rapidocr_onnxruntime找到其安装路径。
    2. config.yaml拷贝出来,放到当前运行目录下
    3. 按需自定义参数修改即可,具体参数解释,参见config.yaml
        engine = RapidOCR(config_path="your.yaml")
        
  • (推荐) 以具体参数传入,参数基本和config.yaml中对应,只是个别名称有所区别。

      class RapidOCR:
        def __init__(
            self,
            text_score: float = 0.5,
            print_verbose: bool = False,
            min_height: int = 30,
            width_height_ratio: float = 8,
            det_use_cuda: bool = False,
            det_model_path: Optional[str] = None,
            det_limit_side_len: float = 736,
            det_limit_type: str = "min",
            det_thresh: float = 0.3,
            det_box_thresh: float = 0.5,
            det_unclip_ratio: float = 1.6,
            det_donot_use_dilation: bool = False,
            det_score_mode: str = "fast",
            cls_use_cuda: bool = False,
            cls_model_path: Optional[str] = None,
            cls_image_shape: List[int] = [3, 48, 192],
            cls_label_list: List[str] = ["0", "180"],
            cls_batch_num: int = 6,
            cls_thresh: float = 0.9,
            rec_use_cuda: bool = False,
            rec_model_path: Optional[str] = None,
            rec_img_shape: List[int] = [3, 48, 320],
            rec_batch_num: int = 6,
            intra_op_num_threads: int = -1,
            inter_op_num_threads: int = -1,
        ):
            pass
    
    engine = RapidOCR()
    
    res, elapse = engine(img, use_det=True, use_cls=True, use_rec=True)
      

输入

支持4种输入类型:Union[str, np.ndarray, bytes, Path, PIL.Image.Image]

输出

类RapidOCR在调用时,有三个参数use_det | use_cls | use_rec,可以控制是否使用检测、方向分类和识别这三部分。不同的参数,决定了不同的输出,如果图像中未检测到有效文字信息,则返回Tupule[None, None]。详细搭配如下:

可视化查看结果

为了便于查看检测和识别结果,该库中封装了VisRes类,可借助该类快速可视化查看结果。

Last updated 24 Apr 2024, 09:27 +0800 . history