Bug: 略微倾斜的竖排文本框会导致检测框顶点顺序错误和识别结果崩坏 #707
Answered
by
yunhao-qian
yunhao-qian
asked this question in
Q&A
问题描述 / Problem DescriptionRapidOCR对一个略微向左下倾斜的竖排文本框裁剪方向错误,导致识别结果崩坏。 具体代码:
这个假设对略微倾斜的竖排文本框不成立(此类排版在旧书刊和古籍中很多)。以下复现中,实际返回的检测框为: 也就是: 但后续 运行环境 / Runtime Environment复现代码 / Reproduction Codefrom PIL import Image, ImageDraw, ImageFont
from rapidocr import RapidOCR
text = (
"国破山河在城春草木深感时花溅泪恨别鸟惊心烽火连三月家书抵万金白头搔更短浑欲不胜簪"
)
font = ImageFont.truetype("/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc", 34)
image = Image.new("RGB", (160, 1640), "white")
draw = ImageDraw.Draw(image)
for i, char in enumerate(text):
y = 32 + i * 39
x = 116 + (38 - 116) * i / (len(text) - 1)
left, _, right, _ = draw.textbbox((0, 0), char, font=font)
draw.text((x - (right - left) / 2, y), char, fill="black", font=font)
image.save("input.png")
ocr = RapidOCR(params={"Global.use_cls": False})
result = ocr("input.png")
print("expected:", text)
print("actual: ", result.txts[0])
print("box: ", result.boxes[0].tolist())程序输出: 可能解决方案 / Possible solutions不要在 可以改成:
这样返回值才是 def order_points_clockwise(self, pts: np.ndarray) -> np.ndarray:
pts = pts.astype("float32")
center = pts.mean(axis=0)
angles = np.arctan2(pts[:, 1] - center[1], pts[:, 0] - center[0])
pts = pts[np.argsort(angles)]
start = np.argmin(pts[:, 0] + pts[:, 1])
return np.roll(pts, -start, axis=0)
|
Answered by
yunhao-qian
Jun 29, 2026
Replies: 2 comments 2 replies
|
我又仔细想了一下,上述的修改建议虽然能修正竖排文字的错误,但是很大程度上会改变旋转接近90度的横排文字的处理方式。具体怎么改还欠研究。 |
0 replies
|
当前代码更多的是针对横排文字处理的。竖排文字我觉得可以单独作为一类来排序。 |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

我看了一下代码,对于我的具体需求,直接给
DBPostProcess.order_points_clockwise()打一个monkey patch就可以解决。至于未来是否有必要在 config 层面提供更好的竖排文字支持,就留给维护者再权衡了。也谢谢您的回复!