1. 内容提取
通过 YOLO 提取需要识别的区域
1.1 安装ultralytics
创建虚拟环境(可选)
# 创建虚拟环境 python -m venv ultralytics-env # 激活虚拟环境 ### 激活虚拟环境将更改 shell 的提示以显示您正在使用的虚拟环境,并修改环境,以便运行时 python可以获得特定版本和安装的 Python。例如: source ultralytics-env/bin/activate # 显示虚拟环境中安装的所有软件包: python -m pip list # 停用/退出虚拟环境 # deactivate
配置阿里云加速
# 配置 Pip 清华镜像源,--user参数表示当前用户生效 pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple --user pip3 config set install.trusted-host pypi.tuna.tsinghua.edu.cn --user # 或者aliyu源: https://mirrors.aliyun.com/pypi/simple # 国外可以使用官方源: https://pypi.org/simple # 查看 Pip 所有配置项, 确认代理配置成功 pip3 config list --user
安装ultralytics
# Install the ultralytics package from PyPI pip install ultralytics # 导出依赖项 # pip freeze > requirements.txt # 安装依赖项 # pip install -r requirements.txt
1.2 编写脚本
cut.py
from ultralytics import YOLO
# Load a model
model = YOLO("best.pt") # pretrained YOLOv8n model
# Run batched inference on a list of images
modelDir = "Downloads/"
# Run inference on 'bus.jpeg' with arguments
results = model.model(modelDir + "bus.jpeg", save=True, imgsz=96)
# Process results list
for result in results:
boxes = result.boxes # Boxes object for bounding box outputs
masks = result.masks # Masks object for segmentation masks outputs
keypoints = result.keypoints # Keypoints object for pose outputs
probs = result.probs # Probs object for classification outputs
obb = result.obb # Oriented boxes object for OBB outputs
result.show() # display to screen
result.save(filename="result.jpg") # save to disk
result.save_txt(txt_file="result.txt")
print(result.tojson())
执行检测python cut.py
2. OCR识别
pip install paddlepaddle-gpu
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。