Пример #1
0
 def test_normalize_origin(self):
     'Check that the origin joint is zero.'
     center_joint = 'HipCenter'
     for frame in normalize_origin(self.frames, center_joint):
         self.assertEqual(
             frame['jointPositions']['jointPositionDict'][center_joint],
             (0.0, 0.0, 0.0))
Пример #2
0
                    split_items, load_option_info, load_skeleton_data, tweak)
from simanneal import Annealer
from normal import normalize_scale, normalize_origin
from copy import deepcopy

#if __name__ == '__main__': # Emacs doesn't like this.

OPTION_INFO = load_option_info('option.json')

## Build path to file.
EXPERIMENT_FILE_PATH = join(KINECT_EXPERIMENT_DIR, OPTION_INFO['dir_name'],
                            OPTION_INFO['file_name'])

## Open file and extract JSON frames data.
FRAMES = normalize_scale(
    normalize_origin(load_skeleton_data(EXPERIMENT_FILE_PATH), 'HipCenter'),
    'HipCenter', 'Head')


class KinectWeightsProblem(Annealer):
    'A class with methods defined for generating weights for classifying joint data.'

    def __init__(self, frames):
        self.frames = frames
        self.state = {
            joint: random.uniform(0.0, 0.5)
            for joint in self.frames[0]['jointPositions']
            ['jointPositionDict'].keys()
        }
        self.ideal_model = {
            joint: (0, 0, 0)
from random import seed
from time import clock

#if __name__ == '__main__': # Emacs doesn't like this.

OPTION_INFO = load_option_info('option.json')

## Build path to file.
EXPERIMENT_FILE_PATH  = join(
    KINECT_EXPERIMENT_DIR,
    OPTION_INFO['dir_name'],
    OPTION_INFO['file_name']
)

## Open file and extract JSON frames data.
FRAMES = normalize_scale(normalize_origin(load_skeleton_data(EXPERIMENT_FILE_PATH), 'HipCenter'),
                         'HipCenter', 'Head')

## Get the joint distances from the frame data.
DISTANCES = map(generate_distances, FRAMES)

## Split the distance data. Use one half for
## training and the other half for testing.
seed(OPTION_INFO['shuffle_seed'])
shuffle(DISTANCES)
TRAINING_DISTANCES, TESTING_DISTANCES = split_items(DISTANCES, 0.5)

seed(OPTION_INFO['training_seed'])
## Train the weights.
WEIGHTS, _ = KinectWeightsProblem(TRAINING_DISTANCES).anneal()