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) # 保存图像文件
参考资料: