-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshow_annotations.py
executable file
·42 lines (33 loc) · 1000 Bytes
/
show_annotations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.image as mpimg
import random
import json
import sys
import os
sys.path.append(os.getcwd())
import config
cfg = config.cfg()
with open(f"DATASET/{cfg.out_folder}/annotations/instances_default.json") as f:
data = json.load(f)
images = data["images"]
labels = data["annotations"]
for idx in range(len(images)):
img_name = images[idx]["file_name"]
print("showing annotation for img: " + img_name)
print("close the window to see the next label")
bbox = labels[idx]["bbox"]
I = mpimg.imread(
f"DATASET/{cfg.out_folder}/images/" + img_name
) # load rendered image
fig, ax = plt.subplots(1)
ax.imshow(I)
plt.axis("off")
[x, y, w, h] = bbox
rect = patches.Rectangle(
(x, y), w, h, linewidth=2, edgecolor="g", facecolor="none"
) # add bounding box annotation
ax.add_patch(rect)
plt.show()