-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_bounding_box.py
35 lines (26 loc) · 965 Bytes
/
plot_bounding_box.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
---------------------------------------------------------------------------------------
by Enting
---------------------------------------------------------------------------------------
import json
import cv2
# Opening JSON file
print("Your inferred JSON path")
f = open(input())
print('Your inferred images path')
image_path = input()
data = json.load(f)
x = int(0)
for i in data['annotations']:
image_id = i['image_id']
score = i['score']
category_id = i['category_id']
x, y, w, h = i['bbox']
fname = image_path+'/'+str(image_id)+'.png'
img = cv2.imread(fname)
cv2.rectangle(img, (int(x),int(y)), (int(x)+int(w),int(y)+int(h)), (0,255,0), 4)
font = cv2.FONT_HERSHEY_SIMPLEX
text = str(score)+'|'+str(category_id)
cv2.putText(img, text, (212, 310), font, 1, (0,255,255), 1, cv2.LINE_AA)
cv2.imwrite('pic_'+str(x)+'.jpg', img)
x = x + 1
f.close()