def extract(self, fileName):
     f = open(fileName, 'r')
     headers = f.readline().split()
     headers = jm.getFileHeader(headers)
     jointsIndices = self.extractor.getJointsIndices(headers)
     frontDirections = []
     centers = []
     sholderVec = []
     for line in f:
         lineInFloats=[float(v) for v in line.split()]
         centers.append(ae.calcJointsAverage(lineInFloats, jointsIndices))
         shouldersVecOnXZPlan = ae.getVecBetweenJoints(headers, lineInFloats,\
                                'ShoulderRight_X', 'ShoulderLeft_X')
         #sholderVec.append(shouldersVecOnXZPlan)
         frontDirections.append([shouldersVecOnXZPlan[2], 0 , -shouldersVecOnXZPlan[0]])
         #frontDirections.append([1,0,0])
     frontDirections = zip(*ma.partsmovingAverage(zip(*frontDirections), 50, 1))
     movingDirections = np.diff(centers, axis=0)
     movingDirections = zip(*ma.partsmovingAverage(zip(*movingDirections), 50, 1))
     advancements = []
     for front, move in zip(frontDirections[:-1], movingDirections):
         if np.abs(front[0])/np.abs(front[2]) > 2:
             front = [ae.length(front),0,0]
         product = np.dot(front, move)
         advancements.append(product)
     return advancements
     """
def getFeatureVec(fileName, chopFactor, firstRun=False, joints=None):
    headers = open(fileName, "r").readline().split()
    # bug in the files
    headers = jm.getFileHeader(headers)
    ver = jm.getVersion(headers)
    featuresNames = []
    vec = []
    jointsHeaders = headers[2:-4]
    for i, h in enumerate(jointsHeaders):  # drop timestamp, frameNum and floor
        if i % 4 == 3:
            continue
        # time, relJoints = ae.getRelative2AncestorPosition(fileName, h, ver)
        if i % 4 != 0:
            continue
        if not joints is None and not h in joints:
            continue
        try:  # for joints that don't have father and grandfather
            time, _, angles, _ = ae.getAngleVec(fileName, h, False, ver)
            if len(angles) == 0:
                continue
        except Exception, e:  # joint without a father
            continue
        if firstRun:
            print "getAngleVec", h, len(vec)

        v, f = analyzeData(time, angles, h.split("_")[0] + " angle ")
        vec += v
        featuresNames += f
Beispiel #3
0
def analyze(inputFile):
    f = open(file, 'r')
    headers = f.readline()
    headers = jm.getFileHeader(headers)
    drops = []
    for line in f:
        lineInFloats=[float(v) for v in line.split()]
        indexHead = headers.index('Head_Y')
        indexSpine = headers.index('SpineShoulder_Y')
        drops.append(lineInFloats[indexHead] - lineInFloats[indexSpine])
    return np.diff(drops)
 def extractLaban(self, fileName, huristic):
     f = open(fileName, 'r')
     headers = f.readline().split()
     headers = jm.getFileHeader(headers)
     jointsIndices = self.getJointsIndices(headers)
     vec = []
     for line in f:
         lineInFloats=[float(v) for v in line.split()]
         #try:
         vec.append(huristic(lineInFloats, headers, jointsIndices))
         #except Exception, e:
             #vec.append(huristic(lineInFloats, headers, jointsIndices))
             #print e
     return vec
def analyze(inputFile):
    f = open(file, 'r')
    headers = f.readline()
    headers = jm.getFileHeader(headers)
    drops = []
    extractor = AbstractLabanAnalyzer.getExtractor(inputFile)
    jointsIndices = extractor.getJointsIndices(headers)
    for line in f:
        for i in jointsIndices:
            
            lineInFloats=[float(v) for v in line.split()]
            indexHead = headers.index('Head_Y')
            indexSpine = headers.index('SpineShoulder_Y')
            drops.append(lineInFloats[indexHead] - lineInFloats[indexSpine])
    return np.diff(drops)
Beispiel #6
0
def analyze(inputFile):
    f = open(file, 'r')
    headers = f.readline()
    headers = jm.getFileHeader(headers)
    jumpsLeft = []
    jumpsRight = []
    for line in f:
        lineInFloats=[float(v) for v in line.split()]
        indexRight = headers.index('AnkleRight_Y')
        indexLeft = headers.index('AnkleLeft_Y')
        jumpsLeft.append(lineInFloats[indexLeft])
        jumpsRight.append(lineInFloats[indexRight])
    jumpsLeft = np.abs(np.diff(jumpsLeft))
    jumpsRight = np.abs(np.diff(jumpsRight))
    return [np.mean([l, r] for l, r in zip(jumpsLeft, jumpsRight))]
Beispiel #7
0
 def animate(self, fileName):
     f= open(fileName, 'r')
     headers=f.readline().split()
     # A fix for a bug that misarranged the columns names in the file 
     headers = jointsMap.getFileHeader(headers)
     print headers
     self.hirarchy = jointsMap.getHirarchy(headers)
     joints = jointsMap.getJoints(headers)
     print joints
     jointsNum = len(joints)
     fileLength=0
     for line in f:
         fileLength+=1
     self.mainWindow.ui.slider.setRange(0, fileLength)
     self.mainWindow.ui.skeletonFileLength = fileLength
     x_t = np.zeros(shape=(jointsNum,fileLength,3)) # empty animation array (3D)
     f= open(fileName, 'r')
     f.readline()
     for i,line in enumerate(f):
         lineF=[float(v) for v in line.split()]
         for j, joint in enumerate(joints):
             x_t[j,i,:] = [lineF[headers.index(joint+'_X')],lineF[headers.index(joint+'_Y')],\
                           lineF[headers.index(joint+'_Z')],]
     
     fig = self.figure
     self.ax = fig.add_axes([0, 0, 1, 1], projection='3d')
     self.ax.axis('on')
     #Adjust data to matplotlib axes
     x_t = x_t[:, :, [2, 0, 1]]
     self.ax.set_xlabel("Z axe")
     self.ax.set_ylabel("X axe")
     self.ax.set_zlabel("Y axe")
     
     # choose a different color for each trajectory
     a = np.linspace(0, 1, jointsNum)
     #self.colors = plt.cm.jet(a)
     from matplotlib.cm import _generate_cmap
     cm= _generate_cmap('Spectral', 256)
     self.colors = cm(a)
     self.colors[8] = [0, 0, 0, 1]
     #cm = matplotlib.colors.LinearSegmentedColormap('jet')
     
     # set up trajectory lines
     self.lines = sum([self.ax.plot([], [], [], '-', c=c) for c in self.colors], [])
     # set up points
     self.pts = sum([self.ax.plot([], [], [], 'o', c=c) for c in self.colors], [])
     # set up lines which create the stick figures
     
     self.stick_lines = [self.ax.plot([], [], [], 'k-')[0] for _ in self.hirarchy]
     
     # prepare the axes limits
     self.ax.set_xlim((np.min(x_t[:,:,0]),np.max(x_t[:,:,0])))
     self.ax.set_ylim((np.min(x_t[:,:,1]),np.max(x_t[:,:,1]))) # note usage of z coordinate
     self.ax.set_zlim((np.min(x_t[:,:,2]),np.max(x_t[:,:,2]))) # note usage of y coordinate
     # set point-of-view: specified by (altitude degrees, azimuth degrees)
     #self.ax.view_init(30, 0)
     #self.ax.set_aspect('auto')
     def myAnimate(i):
         if self.mainWindow.pause or self.mainWindow.stop:
             self.draw()
             return self.lines + self.pts + self.stick_lines
         currTime = self.mainWindow.currTime+1
         self.mainWindow.ui.updateCurrTime(currTime)
         for line, pt, xi in zip(self.lines, self.pts, x_t):
             x, y, z = xi[self.mainWindow.start:currTime].T 
             pt.set_data(x[-1:], y[-1:])
             pt.set_3d_properties(z[-1:])
             
             # trajectory lines
             if self.showTrajectory:
                 line.set_data(x,y)
                 line.set_3d_properties(z)
                 
         if self.showSticks:
             if self.hirarchy is None:
                 QtGui.QMessageBox.information(self,"Can't complete command",\
                                                 'Hirarchy is missing')
                 self.showSticks = False
             else:    
                 for stick_line, (sp, ep) in zip(self.stick_lines, self.hirarchy):
                     stick_line._verts3d = x_t[[sp,ep], currTime, :].T.tolist()
         else:
             for stick_line in self.stick_lines:
                 stick_line._verts3d = [[],[],[]]
                 
         if self.rotate:
             self.ax.view_init(30, currTime)
         return self.lines + self.pts + self.stick_lines
     print self.mainWindow.playingSpeed
     return animation.FuncAnimation(
                 fig, myAnimate,init_func=self.init, interval=1000/self.mainWindow.playingSpeed, blit=True)