-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_DJD.py
131 lines (111 loc) · 3.83 KB
/
create_DJD.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
130
131
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 29 14:49:20 2020
@author: sampatghosh
"""
from os import listdir
import numpy as np
import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
actions_label = ['',
'high-arm-wave',
'horizontal-arm-wave',
'hammer',
'hand-catch',
'forward-punch',
'high-throw',
'draw-x',
'draw-tick',
'draw-circle',
'hand-clap',
'two-hand-wave',
'side-boxing',
'bend',
'forward-kick',
'side-kick',
'jogging',
'tennis-swing',
'tennis-serve',
'golf-swing',
'pick-up-and-throw']
def get_label(file):
action = 0
subject = 0
subset = 0
i = 1
while file[i] != '_':
action = action*10 + int(file[i])
i += 1
i += 2
while file[i] != '_':
subject = subject*10 + int(file[i])
i += 1
i += 2
#while file[i] != '_':
#subset = subset*10 + int(file[i])
#i += 1
return action,subject
def create_DJD(data_dir):
print('Loading MSR 3D Data, data directory %s' % data_dir)
points = [ 1, 8, 10, 12, 0, 7, 9, 11, 19, 2, 3, 6, 4, 13, 15, 17, 5, 14, 16, 18] # MSRAction3D
#points = [ 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 16, 17, 18, 19, 12, 13, 14, 15] # UTD-MAD
#points = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
for file in sorted(listdir(data_dir)): # iterate through the files
action = np.loadtxt(data_dir+'/'+file)[:, :3] # read file
# resize to number aof frames X number of joints X coordinates
action = action.reshape((action.shape[0]//20, 20, 3))
#print(action[0])
#print(action.shape)
R = []
G = []
B = []
#R = np.asarray(np.uint8(R))
#G = np.asarray(np.uint8(G))
#B = np.asarray(np.uint8(B))
# iterate through all the frames in the file
for frame in action:
#minimum = np.min(frame)
#maximum = np.max(frame)
#print(maximum,minimum)
#print(frame)
minX = min(frame[:,0])
maxX = max(frame[:,0])
minY = min(frame[:,1])
maxY = max(frame[:,1])
minZ = min(frame[:,2])
maxZ = max(frame[:,2])
for i in points:
newX = (frame[i][0] - minX) / (maxX - minX)
newY = (frame[i][1] - minY) / (maxY - minY)
newZ = (frame[i][2] - minZ) / (maxZ - minZ)
R.append(newX)
G.append(newY)
B.append(newZ)
R = np.asarray(R).reshape(action.shape[0],20)
G = np.asarray(G).reshape(action.shape[0],20)
B = np.asarray(B).reshape(action.shape[0],20)
R = np.transpose(R)
G = np.transpose(G)
B = np.transpose(B)
R = np.transpose(R)
G = np.transpose(G)
B = np.transpose(B)
DJD = np.ndarray([action.shape[0],20,3])
DJD[:,:,0] = R
DJD[:,:,1] = G
DJD[:,:,2] = B
img = Image.fromarray(np.uint8(DJD*255))
action,subject = get_label(file)
act = str(action)
if action < 10:
act = '0'+str(action)
if subject % 2 == 0:
img.save('/home/sampatghosh/MajorProject/NUCLA_DJD/subject_even/'+file[:-4]+'.jpg')
else:
img.save('/home/sampatghosh/MajorProject/NUCLA_DJD/subject_odd/'+file[:-4]+'.jpg')
#break
basePath = 'Data/MSRAction3DSkeleton'
# basePath = 'UTD_TXT/'
create_DJD(basePath)