forked from alaksana96/darknet-crowdhuman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crowd.py
58 lines (37 loc) · 9.39 KB
/
crowd.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#{"ID": "273275,cd061000af95f691", "gtboxes": [{"tag": "person", "hbox": [285, 223, 25, 27], "head_attr": {"ignore": 0, "occ": 0, "unsure": 0}, "fbox": [260, 221, 71, 232], "vbox": [260, 221, 71, 232], "extra": {"box_id": 0, "occ": 0}}, {"tag": "person", "hbox": [217, 234, 18, 19], "head_attr": {"ignore": 0, "occ": 0, "unsure": 0}, "fbox": [200, 233, 48, 161], "vbox": [200, 233, 48, 161], "extra": {"box_id": 1, "occ": 0}}, {"tag": "person", "hbox": [170, 240, 16, 18], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [148, 238, 55, 156], "vbox": [148, 238, 55, 156], "extra": {"box_id": 2, "occ": 0}}, {"tag": "person", "hbox": [144, 248, 6, 7], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [138, 247, 19, 43], "vbox": [138, 248, 18, 43], "extra": {"box_id": 3, "occ": 1}}, {"tag": "person", "hbox": [126, 243, 7, 8], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [117, 242, 22, 52], "vbox": [122, 243, 16, 51], "extra": {"box_id": 4, "occ": 1}}, {"tag": "person", "hbox": [133, 246, 7, 6], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [129, 244, 14, 42], "vbox": [132, 245, 12, 41], "extra": {"box_id": 5, "occ": 1}}, {"tag": "person", "hbox": [-12, 242, 12, 12], "head_attr": {"ignore": 1, "occ": 1, "unsure": 0}, "fbox": [-20, 241, 39, 102], "vbox": [1, 248, 19, 44], "extra": {"ignore": 0, "box_id": 6, "occ": 1, "unsure": 0}}, {"tag": "mask", "hbox": [24, 244, 19, 41], "head_attr": {}, "fbox": [24, 244, 19, 41], "vbox": [24, 244, 19, 41], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [466, 192, 136, 73], "head_attr": {}, "fbox": [466, 192, 136, 73], "vbox": [466, 192, 136, 73], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [501, 73, 66, 120], "head_attr": {}, "fbox": [501, 73, 66, 120], "vbox": [501, 73, 66, 120], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [573, 97, 28, 62], "head_attr": {}, "fbox": [573, 97, 28, 62], "vbox": [573, 97, 28, 62], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [531, 277, 68, 115], "head_attr": {}, "fbox": [531, 277, 68, 115], "vbox": [531, 277, 68, 115], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [375, 231, 19, 29], "head_attr": {}, "fbox": [375, 231, 19, 29], "vbox": [375, 231, 19, 29], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [382, 192, 38, 25], "head_attr": {}, "fbox": [382, 192, 38, 25], "vbox": [382, 192, 38, 25], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [242, 106, 67, 87], "head_attr": {}, "fbox": [242, 106, 67, 87], "vbox": [242, 106, 67, 87], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [190, 137, 48, 54], "head_attr": {}, "fbox": [190, 137, 48, 54], "vbox": [190, 137, 48, 54], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [328, 243, 27, 77], "head_attr": {}, "fbox": [328, 243, 27, 77], "vbox": [328, 243, 27, 77], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [67, 118, 25, 57], "head_attr": {}, "fbox": [67, 118, 25, 57], "vbox": [67, 118, 25, 57], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [47, 128, 17, 50], "head_attr": {}, "fbox": [47, 128, 17, 50], "vbox": [47, 128, 17, 50], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [66, 213, 19, 30], "head_attr": {}, "fbox": [66, 213, 19, 30], "vbox": [66, 213, 19, 30], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [60, 180, 14, 34], "head_attr": {}, "fbox": [60, 180, 14, 34], "vbox": [60, 180, 14, 34], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [183, 203, 16, 36], "head_attr": {}, "fbox": [183, 203, 16, 36], "vbox": [183, 203, 16, 36], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [253, 198, 32, 20], "head_attr": {}, "fbox": [253, 198, 32, 20], "vbox": [253, 198, 32, 20], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [300, 196, 50, 26], "head_attr": {}, "fbox": [300, 196, 50, 26], "vbox": [300, 196, 50, 26], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [356, 279, 41, 25], "head_attr": {}, "fbox": [356, 279, 41, 25], "vbox": [356, 279, 41, 25], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [458, 29, 79, 76], "head_attr": {}, "fbox": [458, 29, 79, 76], "vbox": [458, 29, 79, 76], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [136, 148, 32, 45], "head_attr": {}, "fbox": [136, 148, 32, 45], "vbox": [136, 148, 32, 45], "extra": {"ignore": 1}}]}
import numpy
import cv2
anno = {"ID": "273275,cd061000af95f691", "gtboxes": [{"tag": "person", "hbox": [285, 223, 25, 27], "head_attr": {"ignore": 0, "occ": 0, "unsure": 0}, "fbox": [260, 221, 71, 232], "vbox": [260, 221, 71, 232], "extra": {"box_id": 0, "occ": 0}}, {"tag": "person", "hbox": [217, 234, 18, 19], "head_attr": {"ignore": 0, "occ": 0, "unsure": 0}, "fbox": [200, 233, 48, 161], "vbox": [200, 233, 48, 161], "extra": {"box_id": 1, "occ": 0}}, {"tag": "person", "hbox": [170, 240, 16, 18], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [148, 238, 55, 156], "vbox": [148, 238, 55, 156], "extra": {"box_id": 2, "occ": 0}}, {"tag": "person", "hbox": [144, 248, 6, 7], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [138, 247, 19, 43], "vbox": [138, 248, 18, 43], "extra": {"box_id": 3, "occ": 1}}, {"tag": "person", "hbox": [126, 243, 7, 8], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [117, 242, 22, 52], "vbox": [122, 243, 16, 51], "extra": {"box_id": 4, "occ": 1}}, {"tag": "person", "hbox": [133, 246, 7, 6], "head_attr": {"ignore": 0, "occ": 1, "unsure": 0}, "fbox": [129, 244, 14, 42], "vbox": [132, 245, 12, 41], "extra": {"box_id": 5, "occ": 1}}, {"tag": "person", "hbox": [-12, 242, 12, 12], "head_attr": {"ignore": 1, "occ": 1, "unsure": 0}, "fbox": [-20, 241, 39, 102], "vbox": [1, 248, 19, 44], "extra": {"ignore": 0, "box_id": 6, "occ": 1, "unsure": 0}}, {"tag": "mask", "hbox": [24, 244, 19, 41], "head_attr": {}, "fbox": [24, 244, 19, 41], "vbox": [24, 244, 19, 41], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [466, 192, 136, 73], "head_attr": {}, "fbox": [466, 192, 136, 73], "vbox": [466, 192, 136, 73], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [501, 73, 66, 120], "head_attr": {}, "fbox": [501, 73, 66, 120], "vbox": [501, 73, 66, 120], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [573, 97, 28, 62], "head_attr": {}, "fbox": [573, 97, 28, 62], "vbox": [573, 97, 28, 62], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [531, 277, 68, 115], "head_attr": {}, "fbox": [531, 277, 68, 115], "vbox": [531, 277, 68, 115], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [375, 231, 19, 29], "head_attr": {}, "fbox": [375, 231, 19, 29], "vbox": [375, 231, 19, 29], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [382, 192, 38, 25], "head_attr": {}, "fbox": [382, 192, 38, 25], "vbox": [382, 192, 38, 25], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [242, 106, 67, 87], "head_attr": {}, "fbox": [242, 106, 67, 87], "vbox": [242, 106, 67, 87], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [190, 137, 48, 54], "head_attr": {}, "fbox": [190, 137, 48, 54], "vbox": [190, 137, 48, 54], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [328, 243, 27, 77], "head_attr": {}, "fbox": [328, 243, 27, 77], "vbox": [328, 243, 27, 77], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [67, 118, 25, 57], "head_attr": {}, "fbox": [67, 118, 25, 57], "vbox": [67, 118, 25, 57], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [47, 128, 17, 50], "head_attr": {}, "fbox": [47, 128, 17, 50], "vbox": [47, 128, 17, 50], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [66, 213, 19, 30], "head_attr": {}, "fbox": [66, 213, 19, 30], "vbox": [66, 213, 19, 30], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [60, 180, 14, 34], "head_attr": {}, "fbox": [60, 180, 14, 34], "vbox": [60, 180, 14, 34], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [183, 203, 16, 36], "head_attr": {}, "fbox": [183, 203, 16, 36], "vbox": [183, 203, 16, 36], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [253, 198, 32, 20], "head_attr": {}, "fbox": [253, 198, 32, 20], "vbox": [253, 198, 32, 20], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [300, 196, 50, 26], "head_attr": {}, "fbox": [300, 196, 50, 26], "vbox": [300, 196, 50, 26], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [356, 279, 41, 25], "head_attr": {}, "fbox": [356, 279, 41, 25], "vbox": [356, 279, 41, 25], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [458, 29, 79, 76], "head_attr": {}, "fbox": [458, 29, 79, 76], "vbox": [458, 29, 79, 76], "extra": {"ignore": 1}}, {"tag": "mask", "hbox": [136, 148, 32, 45], "head_attr": {}, "fbox": [136, 148, 32, 45], "vbox": [136, 148, 32, 45], "extra": {"ignore": 1}}]}
img = cv2.imread('crowdhuman_train/{}.jpg'.format(anno['ID']), 1)
f = open('{}.txt'.format(anno['ID']),'w+')
intPerson = 0
intHead = 1
print(img.shape)
for label in anno['gtboxes']:
x = float(label['fbox'][0])
y = float(label['fbox'][1])
w = float(label['fbox'][2])
h = float(label['fbox'][3])
# cv2.rectangle(img, (x, y), (x + w, y + h), (0,255,0))
xh = label['hbox'][0]
yh = label['hbox'][1]
wh = label['hbox'][2]
hh = label['hbox'][3]
# cv2.rectangle(img, (xh, yh), (xh + wh, y + hh), (255,0,0))
absx = x + w/2
absy = y + h/2
imgw = img.shape[1]
imgh = img.shape[0]
relx = absx / imgw
rely = absy / imgh
relw = w / imgw
relh = h / imgh
f.write('{} {:.4f} {:.4f} {:.4f} {:.4f}\n'.format(intPerson, relx, rely, relw, relh))
f.write('{} {} {} {} {}\n'.format(intHead, xh, yh, wh, hh))
f.close()
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# test = anno
# for box in test['gtboxes']:
# print('{} {} {} {} {}'.format(box['tag'], box['fbox'][0], box['fbox'][1], box['fbox'][2] - box['fbox'][0], box['fbox'][3] - box['fbox'][1]))