VisRes
| def __init__(self, text_score: float = 0.5):
pass
|
参数
- text_score (float, optional): 文本识别结果置信度,值越大,把握越大。取值范围:
[0, 1]
, 默认值是0.5。
| def __call__(
self,
img_content: Union[str, np.ndarray, bytes, Path, Image.Image],
dt_boxes: np.ndarray,
txts: Optional[Union[List[str], Tuple[str]]] = None,
scores: Optional[Tuple[float]] = None,
font_path: Optional[str] = None,
) -> np.ndarray:
pass
|
参数
- img_content (Union[str, np.ndarray, bytes, Path, Image.Image]): 输入图像。
- dt_boxes (np.ndarray): 文本检测所得文本框。
- txts (Optional[Union[List[str], Tuple[str]]], optional): 文本框对应的文本内容。默认为
None
。
- scores (Optional[Tuple[float]], optional): 文本内容对应的置信度,默认为
None
。
- font_path (Optional[str], optional): 字体文件路径,默认为
None
。
使用示例
可视化识别结果时,需要提供字体文件。下载链接:link。
⚠️注意:在rapidocr_onnxruntime>=1.4.0
中支持。
| import cv2
from rapidocr_onnxruntime import RapidOCR, VisRes
engine = RapidOCR()
vis = VisRes()
image_path = "tests/test_files/ch_en_num.jpg"
img = cv2.imread(image_path)
result, elapse_list = engine(img)
boxes, txts, scores = list(zip(*result))
vis_img = vis(img, boxes, txts, scores, font_path)
cv2.imwrite("vis.png", vis_img)
words_boxes = sum(words_boxes, [])
words_all = sum(words, [])
words_scores = [1.0] * len(words_boxes)
vis_img = vis(img, words_boxes, words_all, words_scores, font_path)
cv2.imwrite("vis_single.png", vis_img)
|
| import cv2
from rapidocr_onnxruntime import RapidOCR, VisRes
engine = RapidOCR()
vis = VisRes()
image_path = "tests/test_files/ch_en_num.jpg"
img = cv2.imread(image_path)
result, elapse_list = engine(img)
boxes, txts, scores = list(zip(*result))
res = vis(img, boxes)
cv2.imwrite("only_vis_det.png", res)
|
| import cv2
from rapidocr_onnxruntime import RapidOCR, VisRes
engine = RapidOCR()
vis = VisRes()
image_path = "tests/test_files/ch_en_num.jpg"
img = cv2.imread(image_path)
result, elapse_list = engine(img)
boxes, txts, scores = list(zip(*result))
font_path="resources/fonts/FZYTK.TTF"
res = vis(img, boxes, txts, scores, font_path)
cv2.imwrite("vis_det_rec.png", res)
|