百度 PaddleOCR V3
内置免费 OCR 引擎,基于百度 PaddleOCR,无需额外配置即可使用。
from ascript.ios.screen import Ocr
函数
Ocr(
rect: tuple = None,
pattern: str = None,
confidence: float = 0.1,
image=None,
image_file: str = None).paddleocr_v3()
参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| rect | list | 否 | 圈定屏幕范围 |
| pattern | str | 否 | 正则表达式 |
| confidence | float | 否 | 可信度,默认0.1 |
| image | PIL.Image | 否 | 要识别的图片,默认屏幕截图,如果file参数不为空,则优先使用file |
| image_file | str | 否 | 要识别的图片路径,优先权大于image参数 |
返回值
文字结果字典列表,每条结果包含:
{
"text": "识别到的文本",
"rect": (x1, y1, x2, y2), # 识别到的范围
"center_x": 155.5, # 文字中心点 X
"center_y": 44.0, # 文字中心点 Y
"confidence": 0.95 # 可信度
}
示例
from ascript.ios.screen import Ocr
res = Ocr(rect=[42, 153, 641, 694]).paddleocr_v3()
if res:
for r in res:
print(r['text']) # 文本
print(r['rect']) # 范围
print(r['center_x'], r['center_y']) # 中心点坐标
print(r['confidence']) # 可信度