UniTO/anno2/YearI/SecondSem/BDM/progetto/source/gesture_analyzer.py

72 lines
2.1 KiB
Python
Raw Normal View History

2018-11-22 13:09:11 +01:00
#!/usr/bin/python3
# local imports
from series_util import *
from parser import Parser
from gesture import Gesture
from sys import argv
from multiprocessing import Process
def log(phase, body):
print("["+phase+"]\t" + body)
if __name__ == '__main__':
# obtain command line arguments
dataDir = argv[1]
window = int(argv[2])
step = int(argv[3])
resolution = int(argv[4])
# initialize parser
p = Parser(dataDir)
log("PARSE", "\tFiles found in '" + dataDir+"'.")
# initialize files and divide them by gesture
wFiles1, wFiles2, wFiles3 = p.assign(p.wFiles)
xFiles1, xFiles2, xFiles3 = p.assign(p.xFiles)
yFiles1, yFiles2, yFiles3 = p.assign(p.yFiles)
zFiles1, zFiles2, zFiles3 = p.assign(p.zFiles)
g1 = Gesture(1, p, [wFiles1, xFiles1, yFiles1, zFiles1])
g2 = Gesture(2, p, [wFiles2, xFiles2, yFiles2, zFiles2])
g3 = Gesture(3, p, [wFiles3, xFiles3, yFiles3, zFiles3])
log("ASSIGN", "Assigned files to corresponding gestures.")
log("NORMALIZE", "Normalizing gesture 1.")
p1n = Process(target=g1.normalize_files())
p1n.start()
log("NORMALIZE", "Normalizing gesture 2.")
p2n = Process(target=g2.normalize_files())
p2n.start()
log("NORMALIZE", "Normalizing gesture 3.")
p3n = Process(target=g3.normalize_files())
p3n.start()
p1n.join()
p2n.join()
p3n.join()
# discretize: frames can be found in Gesture.discretized
gaussianInterval = gaussian_interval(resolution)
log("DISCRETIZE", "Discretizing gesture 1. (parallel)")
p1d = Process(target=g1.discretize, args=(gaussianInterval,))
p1d.start()
log("DISCRETIZE", "Discretizing gesture 2. (parallel)")
p2d = Process(target=g2.discretize, args=(gaussianInterval,))
p2d.start()
log("DISCRETIZE", "Discretizing gesture 3. (parallel)")
p3d = Process(target=g3.discretize, args=(gaussianInterval,))
p3d.start()
p1d.join()
p2d.join()
p3d.join()
# print(g1.discretized["w"][0])
# print(get_gesture_words(extract_series(g1.discretized["w"][0].iloc,0), window, step))
# extract gesture words in Gesture.wordSet
g1.get_words(window,step)
print(g1.wordSet)