-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotations_viewer.py
33 lines (29 loc) · 1.09 KB
/
annotations_viewer.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
from DatasetGenerator.bounding_box import bounding_box as bb
import random
import json
import cv2
import os
def get_annotations(annotations_file="./annotation.txt"):
with open(annotations_file) as f:
annotations = f.readlines()
clean_annotations = [a.rstrip() for a in annotations]
paths = [a.split(" ")[0] for a in clean_annotations]
boxes = [a.split(" ")[1:] for a in clean_annotations]
return dict(zip(paths, boxes))
if __name__ == "__main__":
path = "diagrams"
fxy = 0.75 # scale factor
diagrams = os.listdir(path)
annotations = get_annotations("./annotation.txt")
k = None
while k != ord('q'):
choice = f"{path}/{random.choice(diagrams)}"
img = cv2.imread(choice)
img = cv2.resize(img, (0, 0), fx=fxy, fy=fxy)
boxes = annotations[choice]
for box in boxes:
box_ = box.split(",")
bb.add(img, int(box_[0]) * fxy, int(box_[1]) * fxy, int(box_[2]) * fxy, int(box_[3]) * fxy,
box_[4])
cv2.imshow("Annotation viewer - Press q to quit", img)
k = cv2.waitKey(0)