forked from gilbeckers/MultiPersonMatching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_openpose_json.py
130 lines (100 loc) · 3.85 KB
/
parse_openpose_json.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import json
import numpy
def parse_JSON_multi_person(filename):
with open(filename) as data_file:
data = json.load(data_file)
list_of_features = []
keypoints = data["people"]
for k in range(0, len(keypoints)):
person_keypoints = keypoints[k]["pose_keypoints"]
# 18 3D coordinatenkoppels (joint-points)
array = numpy.zeros((18, 2))
arrayIndex = 0
for i in range(0, len(person_keypoints), 3):
if person_keypoints[i+2]> 0: # 0.18 was 0.25 was 0.4
array[arrayIndex][0] = person_keypoints[i]
array[arrayIndex][1] = person_keypoints[i+1]
else:
#logger.debug("openpose certainty(%f) to low index: %d posefile: %s", person_keypoints[i+2], arrayIndex, filename )
array[arrayIndex][0] = 0
array[arrayIndex][1] = 0
arrayIndex+=1
list_of_features.append(array)
return list_of_features
'''
Description parse_JSON_single_person(filename)
Parse the openpose json output and returns an numpy array of 18 rows (body -joint points / keypoints)
so undetected body parts (openpose errors, labeled by openpose as (0,0) )
-> stay (0,0) and can be identified in this way
Parameters:
@:param filename
Returns:
@:returns a numpy array containg 18 2D features
'''
def parse_JSON_single_person(filename):
with open(filename) as data_file:
data = json.load(data_file)
#Keypoints
keypointsPeople1 = data["people"][0]["pose_keypoints"] #enkel 1 persoon => [0]
#18 2D coordinatenkoppels (joint-points)
array = numpy.zeros((18,2))
#list = []
arrayIndex = 0
for i in range(0, len(keypointsPeople1), 3):
array[arrayIndex][0] = keypointsPeople1[i]
array[arrayIndex][1] = keypointsPeople1[i+1]
arrayIndex+=1
#feature = [keypointsPeople1[i], keypointsPeople1[i+1]]
#list.append(feature)
return array
#return list
# the json file is a string var that is currently loaded in memory
# The json file isn't read in this case
def parse_JSON_single_person_as_json(filename):
#data = json.load(filename)
data = filename
#Keypoints
keypointsPeople1 = data["people"][0]["pose_keypoints"] #enkel 1 persoon => [0]
#18 2D coordinatenkoppels (joint-points)
array = numpy.zeros((18,2))
#list = []
arrayIndex = 0
for i in range(0, len(keypointsPeople1), 3):
array[arrayIndex][0] = keypointsPeople1[i]
array[arrayIndex][1] = keypointsPeople1[i+1]
arrayIndex+=1
#feature = [keypointsPeople1[i], keypointsPeople1[i+1]]
#list.append(feature)
return array
#return list
def parse_JSON_multi_person(filename):
with open(filename) as data_file:
data = json.load(data_file)
list_of_features = []
keypoints = data["people"]
for k in range(0, len(keypoints)):
person_keypoints = keypoints[k]["pose_keypoints"]
# 18 3D coordinatenkoppels (joint-points)
array = numpy.zeros((18, 2))
arrayIndex = 0
for i in range(0, len(person_keypoints), 3):
array[arrayIndex][0] = person_keypoints[i]
array[arrayIndex][1] = person_keypoints[i + 1]
arrayIndex += 1
list_of_features.append(array)
return list_of_features
def parse_JSON_multi_person_as_json(filename):
data = filename
list_of_features = []
keypoints = data["people"]
for k in range(0, len(keypoints)):
person_keypoints = keypoints[k]["pose_keypoints"]
# 18 3D coordinatenkoppels (joint-points)
array = numpy.zeros((18, 2))
arrayIndex = 0
for i in range(0, len(person_keypoints), 3):
array[arrayIndex][0] = person_keypoints[i]
array[arrayIndex][1] = person_keypoints[i + 1]
arrayIndex += 1
list_of_features.append(array)
return list_of_features