opencv-python绘制多边形框

import numpy as np
import cv2
import matplotlib.pyplot as plt
import jsonlines
lines = []
# res_0.txt内容如下:
"""
{"type": "text", "bbox": [11, 729, 407, 847], "res": "", "img_idx": 0}
{"type": "text", "bbox": [442, 754, 837, 847], "res": "", "img_idx": 0}
{"type": "title", "bbox": [443, 705, 559, 719], "res": "", "img_idx": 0}
{"type": "figure", "bbox": [10, 1, 841, 294], "res": "", "img_idx": 0}
{"type": "figure_caption", "bbox": [70, 317, 707, 357], "res": "", "img_idx": 0}
{"type": "figure_caption", "bbox": [160, 317, 797, 335], "res": "", "img_idx": 0}
{"type": "table", "bbox": [453, 359, 822, 664], "res": "", "img_idx": 0}
{"type": "table", "bbox": [12, 360, 410, 716], "res": "", "img_idx": 0}
{"type": "table_caption", "bbox": [494, 343, 785, 356], "res": "", "img_idx": 0}
{"type": "table_caption", "bbox": [69, 318, 706, 357], "res": "", "img_idx": 0}
"""
with jsonlines.open("output/1/res_0.txt") as f:
    for line in f:
        h0,w0, h1, w1 = line['bbox']
        lines.append(np.array([[h0,w0],[h0,w1],[h1, w1],[h1,w0]]))
img = cv2.imread('ppstructure/docs/table/1.png')

for line in lines:
    cv2.polylines(img,
                  [line],
                  isClosed=True,
                  color=(255, 255, 0),
                  thickness=3)
cv2.imwrite('output/1/res_2.png', img)  # 保存图像文件

参考资料:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值