You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def main():
try:
# 检查图像文件是否存在
if not os.path.exists(args.image):
raise FileNotFoundError(f"图像文件 '{args.image}' 不存在")
# 使用原始图像
original_img = cv2.imread(args.image)
if original_img is None:
raise ValueError("读取图像失败,请确认图像路径正确且图像未损坏")
else:
original_height, original_width, _ = original_img.shape
print(f"原始图像尺寸: {original_width}x{original_height}")
# 直接使用原始图像进行OCR识别
result = ocr.predict(input=args.image)
for res in result:
res.print()
res.save_to_img("output")
res.save_to_json("output")
except Exception as e:
print(f"OCR处理失败: {str(e)}")
raise RuntimeError(f"OCR处理失败: {str(e)}") from e
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
大家好 我是一个新手菜鸟,可能问题比较简单。感谢大神指导一下 下面是问题
我正在使用 PaddleOCR 进行文字识别,并遇到了一个关于如何将 OCR 结果(即文本框坐标)从预处理后的图像空间映射回原始图像空间的问题。具体来说,我的输入图像在经过 PaddleOCR 的预处理步骤后发生了旋转、拉伸和裁剪等几何变换,导致直接使用的 OCR 输出坐标与原始图像上的实际位置不匹配。
具体情况如下:



输入图像尺寸:800x800
预处理设置:
use_doc_orientation_classify=True
use_doc_unwarping=True
结果中的关键信息:
识别出的文字框坐标(dt_polys 或 rec_boxes)
预处理后的输出图像尺寸仍为 800x800,但内容已被拉伸和裁剪。
获取的坐标信息是基于预处理后的信息坐标,不是基于原图的坐标信息。
我的代码:
import os
import sys
from pathlib import Path
import cv2
import numpy as np
import argparse
from paddleocr import PaddleOCR
配置命令行参数
parser = argparse.ArgumentParser(description='OCR and Translation Tool')
parser.add_argument('--image', type=str, default="11.png", help='Path to input image')
parser.add_argument('--output', type=str, default="translation_result.json", help='Output JSON path')
args = parser.parse_args()
初始化OCR
ocr = PaddleOCR(
use_textline_orientation=True,
lang='ch',
use_tensorrt=False
)
def main():
try:
# 检查图像文件是否存在
if not os.path.exists(args.image):
raise FileNotFoundError(f"图像文件 '{args.image}' 不存在")
if name == "main":
main()
Beta Was this translation helpful? Give feedback.
All reactions