python读取json格式的标注

方法

https://blog.csdn.net/weixin_68789096/article/details/136698639

import json
import cv2
import matplotlib.pyplot as plt
import numpy as np

path="./dom1/dom_DOM.json"
with open(path) as read_file:
    data = json.load(read_file)

shapes=data["shapes"]
num=len(shapes)
print(num)
print(shapes)
gray = cv2.imread('./dom1/dom_DOM.jpg', cv2.IMREAD_GRAYSCALE)
img_color = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
for s in shapes:
    segment=s["points"]
    cv2.line(img_color, (int(segment[0][0]), int(segment[0][1])), (int(segment[1][0]), int(segment[1][1])), (0, 255, 0))

plt.figure()
plt.title(f"Detected segments N {len(shapes)}")
plt.imshow(cv2.cvtColor(img_color, cv2.COLOR_BGR2RGB))
plt.show()

 

posted @ 2024-04-25 18:47  太一吾鱼水  阅读(34)  评论(0编辑  收藏  举报