Replies: 1 comment
-
更新至2.8.0后已解决 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
运行以下quickstart文档中的slice代码,**报错:**TypeError: ocr() got an unexpected keyword argument 'slice'
代码如下:
#使用滑动窗口进行检测和识别
#要使用滑动窗口进行光学字符识别(OCR),可以使用以下代码片段:
#```Python
from paddleocr import PaddleOCR
from PIL import Image, ImageDraw, ImageFont
det_model_dir = './PaddleOCR-main/inference_model/PPOCRdet_v4'
rec_model_dir = './PaddleOCR-main/inference_model/recv4'
cls_model_dir = './PaddleOCR-main/inference_model/clsv2'
初始化OCR引擎
ocr = PaddleOCR(
det_model_dir=det_model_dir,
rec_model_dir=rec_model_dir,
cls_model_dir=cls_model_dir,
use_angle_cls=True,
lang="en"
)
img_path = "./test_1/image1.png"
slice = {'horizontal_stride': 300, 'vertical_stride': 500, 'merge_x_thres': 50, 'merge_y_thres': 35}
results = ocr.ocr(img_path, cls=True, slice=slice)
加载图像
image = Image.open(img_path).convert("RGB")
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("./doc/fonts/simfang.ttf", size=20) # 根据需要调整大小
处理并绘制结果
for res in results:
for line in res:
box = [tuple(point) for point in line[0]]
# 找出边界框
box = [(min(point[0] for point in box), min(point[1] for point in box)),
(max(point[0] for point in box), max(point[1] for point in box))]
txt = line[1][0]
draw.rectangle(box, outline="red", width=2) # 绘制矩形
draw.text((box[0][0], box[0][1] - 25), txt, fill="blue", font=font) # 在矩形上方绘制文本
保存结果
image.save("./PaddleOCR-main/infer_data_collections/test_1/result.jpg")
#```
#此示例初始化了启用角度分类的PaddleOCR实例,并将语言设置为英语。然后调用
ocr
方法,并使用多个参数来自定义检测和识别过程,包括处理图像切片的slice
参数。#要更全面地了解切片操作,请参考切片操作文档。
Beta Was this translation helpful? Give feedback.
All reactions