def getBVHFeatures(body_part, filename_path): """ Extracts X,Y,Z coordinate data per frame for a given body part from a time-series BVH file. BVH file must be recursively parsed prior to the extraction to locate the relevant node to begin processing. Args: body_part (string): body part whose Cartesian coordinate is to be extracted filename_path (string): path of BVH file Returns: list: list of lists of X,Y,Z coordiantes. The number of lists must equal to number of frames in the BVH """ myskeleton = process_bvhfile(filename_path, DEBUG=0) frameTime = myskeleton.dt for t in range(1, myskeleton.frames+1): myskeleton.create_edges_onet(t) nodeFound = findTargetNode(myskeleton.hips, body_part, [])[0] XYZ_displacement = getFrameLevelDisplacements( nodeFound, 1, myskeleton.frames + 1) return XYZ_displacement
def getBVHFeatures(body_part, filename_path): """ Extracts X,Y,Z coordinate data per frame for a given body part from a time-series BVH file. BVH file must be recursively parsed prior to the extraction to locate the relevant node to begin processing. Args: body_part (string): body part whose Cartesian coordinate is to be extracted filename_path (string): path of BVH file Returns: list: list of lists of X,Y,Z coordiantes. The number of lists must equal to number of frames in the BVH """ myskeleton = process_bvhfile(filename_path, DEBUG=0) frameTime = myskeleton.dt for t in range(1, myskeleton.frames + 1): myskeleton.create_edges_onet(t) nodeFound = findTargetNode(myskeleton.hips, body_part, [])[0] XYZ_displacement = getFrameLevelDisplacements(nodeFound, 1, myskeleton.frames + 1) return XYZ_displacement
def open_file(): # read_file file_read load_file global root # Root window global myskeleton global skelscreenedges global gridedges global slidert global myviewport global mycamera global mymenu global mytransport global redraw_grid global redraw_axes global file_prefix # No, you aren't allowed to try to load a new BVH in the middle of playing # back the current BVH... nice try. mytransport.playing = 0 mycanvas = myviewport.canvas if file_prefix == 'NONE': filename = askopenfilename(title = 'Open BVH file', parent=root, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) else: filename = askopenfilename(title = 'Open BVH file', parent=root, \ initialdir = file_prefix, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) print "filename = ", filename # Remove this line later index = filename.rfind('/') # Unix index2 = filename.rfind('\\') # Windows if index != -1: file_prefix = filename[0:index + 1] print "File prefix is ", file_prefix elif index2 != -1: file_prefix = filename[0:index2 + 1] print "File prefix is ", file_prefix # askopenfilename also allows: initialdir = '' # "filename" will have length 0 if user cancels the open. if len(filename) > 0: try: if filename[-3:] == 'bvh': myskeleton2 = process_bvhfile(filename, DEBUG=0) else: myskeleton2 = process_bvhfile(filename, DEBUG=0) print 'wangqi' ## myskeleton2 = profile.run('process_bvhfile(FILE,DEBUG=0)') except IOError: string = "IO Error while attempting to read file." print string error_popup(string) return except SyntaxError: string = "Parse error in BVH file." print string error_popup(string) return except: string = "Unknown error while attempting to read file." print string error_popup(string) return # If we make it here then we've successfully read and parsed the BVH file, # and created myskeleton2 # Undraw all grid edges for edge in gridedges: edge.undraw(mycanvas) # Undraw all skeleton edges for edge in skelscreenedges: edge.undraw(mycanvas) # Don't need to undraw axes - leave as-is # Reset slider to 1 slidert.set(1) # Say farewell to previous skeleton myskeleton = myskeleton2 # Set camera position to something that will hopefully put the skeleton # in view. For Z we want something large so that we're set back from # the skeleton. mycamera.t[0] = int((myskeleton.minx + myskeleton.maxx) / 2) mycamera.t[1] = int((myskeleton.miny + myskeleton.maxy) / 2) if (mycamera.t[1] < 10): mycamera.t[1] = 10 mycamera.t[2] = myskeleton.maxz + 100 mycamera.yrot = 0 mycamera.Recompute() if mymenu.readout: myviewport.draw_readout(mycamera) # Create skelscreenedges[] with sufficient space to handle one # screenedge per skeleton edge. skelscreenedges = myskeleton.make_skelscreenedges(DEBUG=0, arrow='none', circle=1) # Give us some screen edges to display. myskeleton.populate_skelscreenedges(skelscreenedges, slidert.get(), \ DEBUG=0) # print "skelscreenedges after population is:" # print skelscreenedges myplaybar.resetscale(myskeleton.frames) gridedges = grid_setup(myskeleton.minx, myskeleton.minz, \ myskeleton.maxx, myskeleton.maxz, DEBUG=0) redraw_grid = 1 redraw_axes = 1 redraw()
def __init__(self, bvh_filename, camera_x, camera_y, camera_z): self._skeleton = process_bvhfile(bvh_filename) self._camera = Camera(camera_x, camera_y, camera_z, cfx=20, ppdist=30) self._skelscreenedges = self._skeleton.make_skelscreenedges() self._floor_y = None
from skeleton import process_bvhfile import glob import os import json import numpy as np from collections import OrderedDict last_desc = "" files = glob.glob("Data/ACCAD/Transform_Male1_bvh/Short_data/*.bvh") print("Number of data : {}".format(len(files))) for fi in files: try: print("Processing %s" % fi) skel = process_bvhfile(fi) except ValueError: print("Skipping %s" % fi) continue body = OrderedDict() for frame in range(skel.frames): skel.create_edges_onet(frame) for edge in skel.edges[frame]: for vert in (edge.wv1, edge.wv2): if vert.descr is not last_desc: if vert.descr not in body: body[vert.descr] = []
def open_file(): # read_file file_read load_file global root # Root window global myskeleton global skelscreenedges global gridedges global slidert global myviewport global mycamera global mymenu global mytransport global redraw_grid global redraw_axes global file_prefix # No, you aren't allowed to try to load a new BVH in the middle of playing # back the current BVH... nice try. mytransport.playing = 0 mycanvas = myviewport.canvas if file_prefix == 'NONE': filename = askopenfilename(title = 'Open BVH file', parent=root, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) else: filename = askopenfilename(title = 'Open BVH file', parent=root, \ initialdir = file_prefix, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) print "filename = ",filename # Remove this line later index = filename.rfind('/') # Unix index2 = filename.rfind('\\') # Windows if index != -1: file_prefix = filename[0:index+1] print "File prefix is ", file_prefix elif index2 != -1: file_prefix = filename[0:index2+1] print "File prefix is ", file_prefix # askopenfilename also allows: initialdir = '' # "filename" will have length 0 if user cancels the open. if len(filename) > 0: try: myskeleton2 = process_bvhfile(filename,DEBUG=0) ## myskeleton2 = profile.run('process_bvhfile(FILE,DEBUG=0)') except IOError: string = "IO Error while attempting to read file." print string error_popup(string) return except SyntaxError: string = "Parse error in BVH file." print string error_popup(string) return except: string = "Unknown error while attempting to read file." print string error_popup(string) return # If we make it here then we've successfully read and parsed the BVH file, # and created myskeleton2 # Undraw all grid edges for edge in gridedges: edge.undraw(mycanvas) # Undraw all skeleton edges for edge in skelscreenedges: edge.undraw(mycanvas) # Don't need to undraw axes - leave as-is # Reset slider to 1 slidert.set(1) # Say farewell to previous skeleton myskeleton = myskeleton2 # Set camera position to something that will hopefully put the skeleton # in view. For Z we want something large so that we're set back from # the skeleton. mycamera.t[0] = int((myskeleton.minx + myskeleton.maxx)/2) mycamera.t[1] = int((myskeleton.miny + myskeleton.maxy)/2) if (mycamera.t[1] < 10): mycamera.t[1] = 10 mycamera.t[2] = myskeleton.maxz + 100 mycamera.yrot = 0 mycamera.Recompute() if mymenu.readout: myviewport.draw_readout(mycamera) # Create skelscreenedges[] with sufficient space to handle one # screenedge per skeleton edge. skelscreenedges = myskeleton.make_skelscreenedges(DEBUG=0, arrow='none', circle=1) # Give us some screen edges to display. myskeleton.populate_skelscreenedges(skelscreenedges, slidert.get(), \ DEBUG=0) # print "skelscreenedges after population is:" # print skelscreenedges myplaybar.resetscale(myskeleton.frames) gridedges = grid_setup(myskeleton.minx, myskeleton.minz, \ myskeleton.maxx, myskeleton.maxz, DEBUG=0) redraw_grid = 1 redraw_axes = 1 redraw()