Exemplo n.º 1
0
def load_bvh_file(builder,
                  path,
                  scale=1.0,
                  draw_mode=2,
                  offset=None,
                  reference_frame=None,
                  skeleton_model=None,
                  use_clip=False,
                  color=None,
                  visualize=True):
    bvh_reader = BVHReader(path)
    bvh_reader.scale(scale)
    animated_joints = [
        key for key in list(bvh_reader.node_names.keys())
        if not key.endswith("EndSite")
    ]
    o = None
    if bvh_reader.frames is not None:
        skeleton = SkeletonBuilder().load_from_bvh(
            bvh_reader,
            animated_joints,
            reference_frame=reference_frame,
            skeleton_model=skeleton_model)
        motion_vector = MotionVector()
        motion_vector.from_bvh_reader(bvh_reader, False)
        motion_vector.skeleton = skeleton
        if offset is not None:
            motion_vector.translate_root(offset)
        name = path.split("/")[-1]
        o = builder.create_object("animation_controller", name, skeleton,
                                  motion_vector, bvh_reader.frame_time,
                                  draw_mode, visualize, color)
    return o
Exemplo n.º 2
0
def get_bvh_from_str(bvh_str):
    bvh_reader = BVHReader("")
    lines = bvh_str.split("\n")
    # print(len(lines))
    lines = [l for l in lines if len(l) > 0]
    bvh_reader.process_lines(lines)
    return bvh_reader
Exemplo n.º 3
0
def load_motion_from_bvh(filename):
    bvh_reader = BVHReader(filename)
    motion_vector = MotionVector()
    motion_vector.from_bvh_reader(bvh_reader, False)
    animated_joints = list(bvh_reader.get_animated_joints())
    motion_vector.skeleton = SkeletonBuilder().load_from_bvh(
        bvh_reader, animated_joints=animated_joints)
    return motion_vector
Exemplo n.º 4
0
 def load_file(self, filename):
     bvh_reader = BVHReader(str(self.folder_path) + os.sep + filename)
     mv = MotionVector()
     mv.from_bvh_reader(bvh_reader, False)
     animated_joints = list(bvh_reader.get_animated_joints())
     mv.skeleton = SkeletonBuilder().load_from_bvh(
         bvh_reader, animated_joints=animated_joints)
     self.motion_cache[filename] = mv
Exemplo n.º 5
0
 def replace_motion_from_str(self, bvh_str):
     bvh_reader = BVHReader("")
     lines = bvh_str.split("\n")
     print(len(lines))
     lines = [l for l in lines if len(l) > 0]
     bvh_reader.process_lines(lines)
     motion_vector = MotionVector()
     motion_vector.from_bvh_reader(bvh_reader, False)
     self._motion.replace_frames(motion_vector.frames)
Exemplo n.º 6
0
 def load_data_for_normalization(self, data_folder):
     if not data_folder.endswith(os.sep):
         data_folder += os.sep
     bvh_files = glob.glob(data_folder + '*.bvh')
     self.ref_bvh = bvh_files[0]
     self.ref_bvhreader = BVHReader(self.ref_bvh)
     self.skeleton = SkeletonBuilder().load_from_bvh(self.ref_bvhreader)
     for bvh_file_path in bvh_files:
         bvhreader = BVHReader(bvh_file_path)
         filename = os.path.split(bvh_file_path)[-1]
         self.aligned_motions[filename] = bvhreader.frames
Exemplo n.º 7
0
def load_target_skeleton(file_path, scale_factor=1.0):
    skeleton = None
    target_bvh = BVHReader(file_path)
    animated_joints = list(target_bvh.get_animated_joints())
    skeleton = SkeletonBuilder().load_from_bvh(target_bvh,
                                               animated_joints,
                                               add_tool_joints=False)
    for node in list(skeleton.nodes.values()):
        node.offset[0] *= scale_factor
        node.offset[1] *= scale_factor
        node.offset[2] *= scale_factor
    return skeleton
def main():
    global context, pool
    port = 8888
    target_skeleton_file = MODEL_DATA_DIR + os.sep + "iclone_female4.bvh"
    skeleton_model = "iclone"
    target_skeleton_file = None
    parser = argparse.ArgumentParser(
        description="Start the MorphableGraphs REST-interface")
    parser.add_argument(
        "-set",
        nargs='+',
        default=[],
        help="JSONPath expression, e.g. -set $.model_data=path/to/data")
    parser.add_argument("-config_file",
                        nargs='?',
                        default=SERVICE_CONFIG_FILE,
                        help="Path to default config file")
    parser.add_argument("-target_skeleton",
                        nargs='?',
                        default=target_skeleton_file,
                        help="Path to target skeleton file")
    parser.add_argument("-skeleton_scale",
                        nargs='?',
                        default=1.0,
                        help="Scale applied to the target skeleton offsets")
    args = parser.parse_args()
    if os.path.isfile(args.config_file):
        service_config = load_json_file(args.config_file)
        algorithm_config_file = "config" + os.sep + service_config[
            "algorithm_settings"] + "_algorithm.config"
        algorithm_config = load_json_file(algorithm_config_file)
        port = service_config["port"]
        if args.target_skeleton is not None:
            # TODO use custom json file instead
            bvh_reader = BVHReader(args.target_skeleton)
            animated_joints = list(bvh_reader.get_animated_joints())
            target_skeleton = SkeletonBuilder().load_from_bvh(
                bvh_reader, animated_joints=animated_joints)
            target_skeleton.skeleton_model = SKELETON_MODELS[skeleton_model]
        else:
            target_skeleton = None

        context = Context(service_config, algorithm_config, target_skeleton)
    count = cpu_count()
    print("run {} processes on port {}".format(count, port))
    pool = ProcessPoolExecutor(max_workers=count)

    # configure tornado to work with the asynchio loop
    tornado.platform.asyncio.AsyncIOMainLoop().install()
    app.listen(port)
    asyncio.get_event_loop().run_forever()
    pool.shutdown()
Exemplo n.º 9
0
 def slot_load_bvh_str(self):
     filename = QFileDialog.getOpenFileName(self, 'Open File', '.')[0]
     filename = str(filename)
     if os.path.isfile(filename):
         try:
             bvh = BVHReader(filename)
             skeleton = SkeletonBuilder().load_from_bvh(
                 bvh, list(bvh.get_animated_joints()))
             self.data = skeleton.to_unity_format()
             print("loaded bvh string from", filename)
         except Exception as e:
             self.data = None
             print("Could not read file", e.args, filename)
Exemplo n.º 10
0
 def replace_motion_from_file(self, filename):
     if filename.endswith(".bvh"):
         bvh_reader = BVHReader(filename)
         motion_vector = MotionVector()
         motion_vector.from_bvh_reader(bvh_reader, False)
         self._motion.replace_frames(motion_vector.frames)
         self.currentFrameNumber = 0
         self.updateTransformation()
         self.update_scene_object.emit(-1)
         self.updated_animation_frame.emit(self.currentFrameNumber)
     elif filename.endswith("_mg.zip"):
         self.scene_object.scene.attach_mg_state_machine(
             self.scene_object, filename)
         self._motion = self.scene_object._components[
             "morphablegraph_state_machine"]
         self._motion.set_target_skeleton(self._visualization.skeleton)
         self.activate_emit = False
     elif filename.endswith("amc"):
         amc_frames = parse_amc_file(filename)
         motion_vector = MotionVector()
         motion_vector.from_amc_data(self._visualization.skeleton,
                                     amc_frames)
         self._motion.replace_frames(motion_vector.frames)
         self._motion.mv.frame_time = 1.0 / 120
         self.currentFrameNumber = 0
         self.updateTransformation()
         self.update_scene_object.emit(-1)
         self.updated_animation_frame.emit(self.currentFrameNumber)
Exemplo n.º 11
0
def load_motion(path, skeleton_type=None):
    bvh = BVHReader(path)
    mv = MotionVector()
    mv.from_bvh_reader(bvh)
    skeleton = SkeletonBuilder().load_from_bvh(bvh)
    skeleton.skeleton_model = load_skeleton_model(skeleton_type)
    return skeleton, mv
Exemplo n.º 12
0
    def __init__(self,
                 elementary_action,
                 motion_primitive,
                 data_repo,
                 functional_motion_data,
                 npc,
                 skeleton_json,
                 knots,
                 n_joints):
        """

        :param functional_motion_data (numpy.array<3d> n_samples * n_coeffs * n_dims): each dimension of motion data is
        represented as a function, the dimension of motion data is: first three channels are Hips' translation, four
        channels for the orientation of each joint
        :return:
        """
        self.functional_motion_data = functional_motion_data
        self.motion_primitive = motion_primitive
        self.elementary_action = elementary_action
        self.cartesian_motion_data = convert_quat_functional_data_to_cartesian_functional_data(elementary_action,
                                                                                               motion_primitive,
                                                                                               data_repo,
                                                                                               skeleton_json,
                                                                                               functional_motion_data,
                                                                                               knots)
        self.npc = npc
        self.knots = knots
        skeleton_bvh = os.path.join(os.path.dirname(__file__), r'../../../skeleton.bvh')
        bvhreader = BVHReader(skeleton_bvh)
        self.skeleton = SkeletonBuilder().load_from_bvh(bvhreader)
        self.skeleton_json = skeleton_json
        self.data_repo = data_repo
        self.n_joints = n_joints
        self.len_weights = self.n_joints + LEN_CARTESIAN
        self.pca = PCA(n_components=self.npc)
Exemplo n.º 13
0
def gen_synthetic_semantic_annotation_for_screw(elementary_action,
                                                motion_primitive):
    data_folder = get_aligned_data_folder(elementary_action,
                                          motion_primitive)
    # if motion_primitive == 'retrieve':
    #     semantic_annotation_data = {'annotation_list': ['retrieveTool', 'start', 'end'],
    #                                 'data': {}}
    #     bvhfiles = glob.glob(os.path.join(data_folder, '*.bvh'))
    #     bvhreader = BVHReader(bvhfiles[0])
    #     n_frames = len(bvhreader.frames)
    #     for filename in bvhfiles:
    #
    # semantic_annotation_data = {'annotation_list': ['fastenerContact', 'toolActivity', 'retrieveTool'],
    #                             'data': {}}
    # if
    semantic_annotation_data = {'annotation_list': ['start', 'end'],
                                'data': {}}
    bvhfiles = glob.glob(os.path.join(data_folder,'*.bvh'))
    bvhreader = BVHReader(bvhfiles[0])
    n_frames = len(bvhreader.frames)
    for item in bvhfiles:
        filename = os.path.split(item)[-1]
        start = np.zeros(n_frames)
        start[0] = 1.0
        end = np.zeros(n_frames)
        end[-1] = 1.0
        semantic_annotation_data['data'][filename] = {'start': start.tolist(),
                                                      'end': end.tolist()}
    output_path = data_folder + os.sep + '_'.join([elementary_action,
                                                   motion_primitive,
                                                   'semantic',
                                                   'annotation.json'])
    with open(output_path, 'w') as outfile:
        json.dump(semantic_annotation_data, outfile)
Exemplo n.º 14
0
 def load_motion_from_files_for_DTW(self, folder_path):
     if not folder_path.endswith(os.sep):
         folder_path += os.sep
     print("search bvh files in " + folder_path)
     motion_files = glob.glob(folder_path + '*.bvh')
     print(str(len(motion_files)) + " are found!")
     for bvh_file_path in motion_files:
         bvhreader = BVHReader(bvh_file_path)
         filename = os.path.split(bvh_file_path)[-1]
         self.aligned_motions[filename] = bvhreader.frames
     self.ref_bvhreader = bvhreader
def import_motion(db,new_id, skeleton, skeleton_name, filename):
    bvh = BVHReader(filename)
    name = filename.split(os.sep)[-1]
    mv = MotionVector()
    mv.from_bvh_reader(bvh)
    mv.skeleton = skeleton
    data = mv.to_db_format()
    public = 0
    n_frames = mv.n_frames
    data =  bson.dumps(data)
    meta_data = b"x00"
    db.insert_motion(new_id, skeleton_name, name, data, meta_data, n_frames, public)
Exemplo n.º 16
0
def gen_synthetic_semantic_annotation_pick_and_place(elementary_action,
                                                     motion_primitive):
    data_folder = get_aligned_data_folder(elementary_action,
                                          motion_primitive)
    semantic_annotation_data = {'annotation_list': ['leftHandContact', 'rightHandContact', 'leftFootContact',
                                                    'rightFootContact', 'start', 'end'],
                                'data':{}}
    bvhfiles = glob.glob(data_folder + os.sep + '*.bvh')
    bvhreader = BVHReader(bvhfiles[0])
    n_frames = len(bvhreader.frames)
    for item in bvhfiles:
        filename = os.path.split(item)[-1]
        leftHand = np.zeros(n_frames)
        rightHand = np.zeros(n_frames)
        leftFoot = np.ones(n_frames)
        rightFoot = np.ones(n_frames)
        start = np.zeros(n_frames)
        start[0] = 1.0
        end = np.zeros(n_frames)
        end[-1] = 1.0
        if motion_primitive == 'first' and 'left' in elementary_action.lower():
            leftHand[-1] = 1
        elif motion_primitive == 'first' and 'right' in elementary_action.lower():
            rightHand[-1] = 1
        elif motion_primitive == 'first' and 'both' in elementary_action.lower():
            leftHand[-1] = 1
            rightHand[-1] = 1
        elif motion_primitive == 'second' and 'left' in elementary_action.lower():
            leftHand[:] = 1
        elif motion_primitive == 'second' and 'right' in elementary_action.lower():
            rightHand[:] = 1
        elif motion_primitive == 'second' and 'both' in elementary_action.lower():
            leftHand[:] = 1
            rightHand[:] = 1
        else:
            ValueError('motion primitive type is not support!')
        semantic_annotation_data['data'][filename] = {'leftHandContact': leftHand.tolist(),
                                                      'rightHandContact': rightHand.tolist(),
                                                      'leftFootContact': leftFoot.tolist(),
                                                      'rightFootContact': rightFoot.tolist(),
                                                      'start': start.tolist(),
                                                      'end': end.tolist()}
    output_path = data_folder + os.sep + '_'.join([elementary_action,
                                                   motion_primitive,
                                                   'semantic',
                                                   'annotation.json'])
    with open(output_path, 'w') as outfile:
        json.dump(semantic_annotation_data, outfile)
 def get_reduced_euler_frames(self, load_data=True, export_data=False):
     reduced_euler_frames_filename = os.path.join(
         self.data_analysis_folder, 'reduced_euler_frames.json')
     if load_data and os.path.exists(reduced_euler_frames_filename):
         reduced_euler_frames_dic = load_json_file(
             reduced_euler_frames_filename)['data']
     else:
         bvhreader = BVHReader(self.skeleton_bvh)
         reduced_euler_frames_dic = {}
         for filename, frames in self.spatial_data.items():
             reduced_euler_frames_dic[
                 filename] = convert_euler_frames_to_reduced_euler_frames(
                     bvhreader, frames)
     if export_data:
         output_data = {'data': reduced_euler_frames_dic}
         write_to_json_file(reduced_euler_frames_filename, output_data)
     return reduced_euler_frames_dic
 def create_quat_spline_from_bvhfile(self, bvhfile, n_basis, degree=3):
     bvhreader = BVHReader(bvhfile)
     quat_frames = convert_euler_frames_to_quaternion_frames(
         bvhreader, bvhreader.frames)
     fd = FunctionalData()
     functional_coeffs = fd.convert_motion_to_functional_data(
         quat_frames, n_basis, degree)
     functional_coeffs = mgrd.asarray(functional_coeffs.tolist())
     knots = fd.knots
     sspm = mgrd.QuaternionSplineModel.load_from_json(
         self.skeleton, self.mm_data['sspm'])
     sspm.motion_primitive = self.motion_primitive
     coeffs_structure = mgrd.CoeffStructure(
         len(self.mm_data['sspm']['animated_joints']),
         mgrd.CoeffStructure.LEN_QUATERNION,
         mgrd.CoeffStructure.LEN_ROOT_POSITION)
     quat_spline = mgrd.QuatSpline(functional_coeffs, knots,
                                   coeffs_structure, degree, sspm)
     return quat_spline
Exemplo n.º 19
0
def gen_foot_contact_annotation(bvhfile, feature_joints,
                                motion_primitive_model):
    """

    :param bvhfile:
    :param feature_joints: [left joint, right joint]
    :return:
    """
    bvhreader = BVHReader(bvhfile)
    n_frames = len(bvhreader.frames)
    left_joint_speed, right_joint_speed = get_joint_speed(
        bvhreader, feature_joints)
    start_anno = np.zeros(n_frames)
    start_anno[0] = 1.0
    end_anno = np.zeros(n_frames)
    end_anno[-1] = 1.0
    semantic_annotation = {
        'LeftFootContact': [],
        'RightFootContact': [],
        'start': start_anno.tolist(),
        'end': end_anno.tolist()
    }
    if motion_primitive_model == 'leftStance':
        semantic_annotation['RightFootContact'] = np.ones(n_frames).tolist()
        semantic_annotation['LeftFootContact'] = gen_annotation(
            left_joint_speed, right_joint_speed, 'left')
    elif motion_primitive_model == 'rightStance':
        semantic_annotation['RightFootContact'] = gen_annotation(
            left_joint_speed, right_joint_speed, 'right')
        semantic_annotation['LeftFootContact'] = np.ones(n_frames).tolist()
    elif motion_primitive_model == 'sideStep':
        semantic_annotation['RightFootContact'] = gen_annotation(
            left_joint_speed, right_joint_speed, 'sideStep')
        semantic_annotation['LeftFootContact'] = gen_annotation(
            left_joint_speed, right_joint_speed, 'sideStep')
    else:
        raise NotImplementedError
    return semantic_annotation
Exemplo n.º 20
0
 def normalize_root(self, origin_point):
     """set the offset of root joint to (0, 0, 0), and shift the motions to
        original_point, if original_point is None, the set it as (0, 0, 0)
     """
     origin_point = [origin_point['x'],
                     origin_point['y'],
                     origin_point['z']]
     if self.ref_bvh is not None:
         self.ref_bvhreader = BVHReader(self.ref_bvh)
     elif self.bvhreader is not None:
         self.ref_bvhreader = self.bvhreader
     else:
         raise ValueError('No reference BVH file for skeleton information')
     self.ref_bvhreader.node_names['Hips']['offset'] = [0, 0, 0]
     skeleton = SkeletonBuilder().load_from_bvh(self.ref_bvhreader)
     for filename, frames in self.aligned_motions.items():
         height_1 = get_cartesian_coordinates_from_euler_full_skeleton(self.ref_bvhreader,
                                                                       skeleton,
                                                                       'Bip01_R_Toe0',
                                                                       frames[0])[1]
         height_2 = get_cartesian_coordinates_from_euler_full_skeleton(self.ref_bvhreader,
                                                                       skeleton,
                                                                       'Bip01_L_Toe0',
                                                                       frames[0])[1]
         height_3 = get_cartesian_coordinates_from_euler_full_skeleton(self.ref_bvhreader,
                                                                       skeleton,
                                                                       'Bip01_R_Toe0',
                                                                       frames[-1])[1]
         height_4 = get_cartesian_coordinates_from_euler_full_skeleton(self.ref_bvhreader,
                                                                       skeleton,
                                                                       'Bip01_L_Toe0',
                                                                       frames[-1])[1]
         height_offset = (height_1 + height_2 + height_3 + height_4)/4.0
         self.aligned_motions[filename] = self.translate_to_original_point(
             frames,
             origin_point,
             height_offset)
Exemplo n.º 21
0
import bson
import argparse
from motion_database import MotionDatabase
from anim_utils.utilities.io_helper_functions import load_json_file
from anim_utils.animation_data import BVHReader, SkeletonBuilder

CONFIG_FILE = "db_server_config.json"

if __name__ == "__main__":
    config = load_json_file(CONFIG_FILE)
    parser = argparse.ArgumentParser(description='Import skeleton to db.')
    parser.add_argument('name', nargs='?', help='name')
    parser.add_argument('skeleton_path', nargs='?', help='BVH file')
    args = parser.parse_args()
    if args.name is not None and args.skeleton_path is not None:
        db = MotionDatabase()
        db_path = config["db_path"]
        db.connect(db_path)
        bvh = BVHReader(args.skeleton_path)
        skeleton = SkeletonBuilder().load_from_bvh(bvh)
        data = skeleton.to_unity_format()
        meta_data = dict()
        meta_data["cos_map"] = dict()
        meta_data["joints"] = dict()
        meta_data["joint_constraints"] = dict()
        data = bson.dumps(data)
        meta_data = bson.dumps(meta_data)
        print("add new skeleton", args.name)
        db.add_new_skeleton(args.name, data, meta_data)
        db.close()
Exemplo n.º 22
0
 def set_ref_motion(self, filepath):
     ref_filename = os.path.split(filepath)[-1]
     ref_bvh = BVHReader(filepath)
     self.ref_motion['filename'] = ref_filename
     self.ref_motion['frames'] = ref_bvh.frames
def load_skeleton(filename):
    bvh = BVHReader(filename)
    skeleton = SkeletonBuilder().load_from_bvh(bvh)
    return skeleton
 def load_from_file(self, file_name):
     bvh = BVHReader(file_name)
     self.skeleton = SkeletonBuilder().load_from_bvh(bvh)
Exemplo n.º 25
0
def calc_bitvector_walking(frames,
                           features,
                           skeleton=None,
                           verbose=False,
                           threshold=0.2):
    """ Detect a bit vector for each frame in the motion

    Parameters
    ----------
    frames : numpy.ndarray
        The frames of the walking motion
    feature : list of str
        The Food features
    skeleton: animation_data.skeleton.Skeleton
        The skeleton to be used. If None, the default interact skeleton is
        used.
    verbose: bool
        Wether to print / plot debug information or not
    threshold: int
        T.B.D.

    Returns
    -------
    A list containing a bit vector for each frame. Each bit vector has one
    element for each feature, indicating wether this feature is on the ground
    or not.
    """
    if skeleton is None:
        reader = BVHReader('skeleton.bvh')
        skeleton = Skeleton(reader)

    if isinstance(features, str):
        features = [features]

    jointpositions = {}

    # Get cartesian position frame wise. Change this for performance?
    for feature in features:
        jointpositions[feature] = []
        for frame in frames:
            jointpositions[feature].append(
                get_cartesian_coords(reader, skeleton, feature, frame))
        jointpositions[feature] = np.array(jointpositions[feature])

    bitvector = {}
    xz_threshold = threshold
    relativ_velo = {}

    for feature in features:
        dif = np.diff(jointpositions[feature], axis=0)
        relativ_velo[feature] = dif[:, 0]**2 + dif[:, 1]**2 + dif[:, 2]**2
        bitvector[feature] = relativ_velo[feature] < threshold
        bitvector[feature] = np.concatenate(
            (bitvector[feature], [bitvector[feature][-1]],
             [bitvector[feature][-1]]))

    height_bitvectors = [{feature: 0
                          for feature in features}
                         for i in range(frames.shape[0])]

    height_threshold = threshold

    jointpositions_y = {}
    for feature in features:
        jointpositions_y[feature] = [pos[1] for pos in jointpositions[feature]]
        for i in range(len(jointpositions_y[feature])):
            if jointpositions_y[feature][i] < height_threshold:
                height_bitvectors[i][feature] = 1

    bitvectors_smoothed = smooth_bitvectors(bitvector, threshold=8)
    bitvectors_smoothed = smooth_bitvectors(bitvectors_smoothed, threshold=4)
    bitvectors_smoothed = smooth_bitvectors(bitvectors_smoothed, threshold=2)
    bitvectors_smoothed = smooth_bitvectors(bitvectors_smoothed, threshold=1)

    if verbose:
        # Plots:

        plt.figure()
        for feature in ['Bip01_L_Toe0', 'Bip01_R_Toe0']:
            plt.plot(bitvectors_smoothed[feature], label=feature)
        plt.legend()
        plt.ylim([0, 2])
        plt.title('walk')
        plt.xlabel('frameindex')
        plt.ylabel('bitvalue')
        plt.figure()
        for feature in ['Bip01_L_Toe0', 'Bip01_R_Toe0']:
            plt.plot(bitvector[feature], label=feature)
        plt.legend()
        plt.ylim([0, 2])
        plt.title('walk')
        plt.xlabel('frameindex')
        plt.ylabel('bitvalue')

        #        plt.figure()
        #        for feature in ['LeftFoot', 'RightFoot']:
        #            plt.plot(bitvectors_smoothed[feature], label=feature)
        #        plt.legend()
        #        plt.ylim([0, 2])
        #        plt.title('walk')
        #        plt.xlabel('frameindex')
        #        plt.ylabel('bitvalue')

        plt.figure()
        line_x = list(range(len(relativ_velo[features[0]])))
        line_y = [xz_threshold] * len(line_x)
        plt.plot(line_x, line_y)
        for feature in features:
            plt.plot(relativ_velo[feature], label=feature)
        plt.legend()
        plt.xlabel('frameindex')
        plt.ylabel('relativ velocity in xz')

        #        plt.figure()
        #        for feature in features:
        #            tmp = [vector[feature] for vector in height_bitvectors]
        #            plt.plot(tmp, label=feature)
        #        plt.legend()
        #        plt.ylim([0, 2])
        #        plt.title('walk')
        #        plt.xlabel('frameindex')
        #        plt.ylabel('bitvalue (using height)')
        #
        #        plt.figure()
        #        line_x = range(len(relativ_velo_xz[features[0]]))
        #        line_y = [xz_threshold] * len(line_x)
        #        plt.plot(line_x, line_y)
        #        for feature in features:
        #            plt.plot(jointpositions_y[feature], label=feature)
        #        plt.legend()
        #        plt.xlabel('frameindex')
        #        plt.ylabel('relativ velocity in xz')

        plt.ioff()
        plt.show()

    return bitvectors_smoothed
Exemplo n.º 26
0
def splitt_motion(frames,
                  keyframes,
                  mname,
                  skeleton_file='skeleton.bvh',
                  outputpath=''):
    """ Splitt a Motion by the given Keyframes

    Parameters
    ----------
    frames : numpy.ndarray
        The frames of the walking motion
    keyframes : dict of list of int
        A dictionary containing a list for each feature.
        Each list contains all Keyframes for this feature.
    mname: string
        Subfix of the splitted motions (i.e. the original name of the
        motion)
    skeleton_file: string (optional)
        The path to the skeleton file. Default is the 'skeleton.bvh' in the
        current folder
    outputpath: string (optional)
        The path where to save the motions. Default is the current folder

    Returns
    -------
    None
    """

    # Calc number of steps for status update
    n = 0.0
    counter = 0.0
    for feature in keyframes:
        n += len(keyframes[feature])

    tmpmins = []
    tmpmax = []
    for feature in keyframes:
        tmpmins.append(min(keyframes[feature])[0])
        tmpmax.append(max(keyframes[feature])[1])
    firstframe = min(tmpmins)
    lastframe = max(tmpmax)

    reader = BVHReader(skeleton_file)
    skel = SkeletonBuilder().load_from_bvh(reader)
    for feature in keyframes:
        # save first step:
        if firstframe in keyframes[feature][0]:
            keyframe = keyframes[feature][0]
            subframes = frames[keyframe[0]:keyframe[1]]
            name = 'begin_' + str(keyframe[0]) + '_' + str(keyframe[1]) \
                + '_' + feature + '_' + mname
            BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889)
            keyframes[feature] = keyframes[feature][1:]

        # last step:
        if lastframe in keyframes[feature][-1]:
            keyframe = keyframes[feature][-1]
            subframes = frames[keyframe[0]:keyframe[1]]
            name = 'end_' + str(keyframe[0]) + '_' + str(keyframe[1]) \
                + '_' + feature + '_' + mname
            BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889)
            keyframes[feature] = keyframes[feature][:-1]

        for keyframe in keyframes[feature]:
            subframes = frames[keyframe[0]:keyframe[1]]
            name = str(keyframe[0]) + '_' + str(keyframe[1]) \
                + '_' + feature + '_' + mname
            BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889)

            counter += 1.0
Exemplo n.º 27
0
def load_skeleton(path, skeleton_type=None):
    bvh = BVHReader(path)
    skeleton = SkeletonBuilder().load_from_bvh(bvh)
    skeleton.skeleton_model = load_skeleton_model(skeleton_type)
    return skeleton