2

我正在使用此代码

with open('frame 0001.json') as json_file:
    json_dict = json.load(json_file)
    shape = (1920, 1052)
    canvas = np.zeros(shape)
    for obj in json_dict["objects"]:
        pts = [((round(p["x"] - 1)), (round(p["y"]))) for p in obj["polygon"]]
        mp.fill_polygon(pts, canvas, obj["classIndex"])
    pic = canvas.transpose()
plt.imshow(pic)
plt.show()

将 JSON 文件转换为绘图。但是,我想将首先设置的颜色更改obj["classIndex"] 为另一种颜色。在打印情节时,我发现情节看起来像这样

[[5. 5. 5. 5.]
 [5. 5. 5. 5.]
 [5. 5. 5. 5.]
 ...
 [4. 4. 4. 4.]
 [4. 4. 4. 4.]
 [0. 0. 0. 0.]]

我以前从未见过这种情况。我将如何将这些值更改为 RGB?我之前设置的。我知道我可以使用

colors = [
    (0, 0, 0, 255),
    (100, 100, 100, 255),
    (204, 0, 0, 255),
    (0, 174, 0, 255),
    (102, 51, 153, 255),
    (0, 0, 155, 255),
    (255, 102, 0, 255),

for idx, c in enumerate(colors):
    pic[np.all(pic == idx)] = c

改变这样的事情

[[0 0 0 0]
 [0 0 0 0]
 [0 0 0 0]]

对此

[[0 0 0 255]
 [0 0 0 255]
 [0 0 0 255]
 [0 0 0 255]]

但是,我以前从未使用过这样的东西

[[5. 5. 5. 5.]
 [5. 5. 5. 5.]
 [5. 5. 5. 5.]]

4

0 回答 0