-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_json_combiner.py
More file actions
38 lines (34 loc) · 1.51 KB
/
class_json_combiner.py
File metadata and controls
38 lines (34 loc) · 1.51 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 29 16:36:59 2019
@author: wangz29
"""
import os, json
# Functor class for combining the json files generated by OpenPose
class JsonCombiner(object):
def combine(self, input_path):
output_file = input_path + '_raw'
combined = []
# Start
json_files = [pos_json for pos_json in os.listdir(input_path) if pos_json.endswith('.json')]
# We need both the json and an index number so use enumerate()
for index, js in enumerate(json_files):
with open(os.path.join(input_path, js)) as json_file:
json_text = json.load(json_file)
meta_data = json_text['people']
if(len(meta_data) > 0):
# Only extracts the metadata for the first person since all ids are -1 for some reason
# Should be looked into in the future
first_person = meta_data[0]
combined.append(first_person)
else:
combined.append({})
# print(index, ' no data')
with open(output_file, 'w') as json_file:
json.dump(combined, json_file)
print('Finished combining')
return output_file
# input_path = 'F:\\openpose-1.5.0-binaries-win64-gpu-python-flir-3d_recommended\\openpose-1.5.0-binaries-win64-gpu-python-flir-3d_recommended\\output\\Test_2'
# output_file = 'F:\\Data\\Test_2_raw.json'
# myCombiner = JsonCombiner()
# print(myCombiner.combine(input_path, output_file))