You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python如何处理OCR输出的元组列表,按指定格式打印坐标与识别文本

实现代码

你在获取到bounds变量后,直接运行以下代码即可得到目标格式的输出:

for idx, entry in enumerate(bounds):
    # 拆分坐标、识别文本,忽略置信度
    coord_list, text, _ = entry
    # 展开嵌套坐标为一维数组
    flatten_coord = [val for point in coord_list for val in point]
    # 打印坐标和文本,repr保证输出带单引号的字符串格式
    print(flatten_coord, end=",\n")
    print(repr(text))
    # 两组内容之间打印分隔线,最后一条结果后不打印
    if idx != len(bounds) - 1:
        print("##################")

补充说明

如果不需要输出文本两侧的单引号,把print(repr(text))改成print(text)即可。

内容的提问来源于stack exchange,提问作者Nithin Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 09:45:03