Пример #1
0
    def test_set_params(self):
        r = c3d.Reader(Zipload._get('sample08.zip', 'TESTDPI.c3d'))
        w = c3d.Writer(
            point_rate=r.point_rate,
            analog_rate=r.analog_rate,
            point_scale=r.point_scale,
        )
        w.add_frames([(p, a) for _, p, a in r.read_frames()])

        h = io.BytesIO()
        w.set_start_frame(255)
        w.set_point_labels(r.point_labels)
        w.set_analog_labels(r.analog_labels)
        w.set_analog_general_scale(r.get('ANALOG:GEN_SCALE').float_value)

        # Screen axis
        X, Y = '-Y', '+Z'
        w.set_screen_axis()
        w.set_screen_axis(X, Y)
        X_v, Y_v = w.get_screen_xy_strings()
        assert X_v == X and Y == Y_v, 'Mismatch between set & get screen axis.'
        assert np.all(np.equal(r.point_labels,
                               w.point_labels)), 'Expected labels to be equal.'

        test_name = 'TEST_PARAM'
        test_string = 'lorem ipsum'
        w.point_group.add_str(test_name, 'void descriptor', test_string)

        assert w.point_group.get(test_name).total_bytes == len(test_string), \
               "Mismatch in number of bytes encoded by 'Group.add_str'"

        w.write(h)
Пример #2
0
def write_c3d_with_model(model, dataloader, file):
    writer = c3d.Writer()
    model.eval()
    with torch.no_grad():
        for i, actor in enumerate(dataloader):
            frame = actor[
                0]  # take the unclean data frame only to give to the model
            out = model(frame)
            outs = out.reshape(-1, 3, 56).transpose(1, 2).unbind()
            null_tensor = torch.zeros(56,
                                      2,
                                      dtype=torch.float32,
                                      device=DEVICE)
            np_outs = [
                torch.cat((t, null_tensor), dim=1).cpu().numpy() for t in outs
            ]
            for t in np_outs:
                writer.add_frames([t, numpy.zeros((0, 1))])
            if (i + 1) % 100 == 0:
                print('Processed frames [{}/{}]'.format(
                    i + 1, len(dataloader)))

    with open(file, 'wb') as f:
        print("Writing data to {}...".format(file))
        writer.write(f)
Пример #3
0
 def test_paramsd(self):
     r = c3d.Reader(self._get('params.zip', 'TESTDPI.c3d'))
     w = c3d.Writer(
         point_rate=r.point_rate,
         analog_rate=r.analog_rate,
         point_scale=r.point_scale,
         gen_scale=r.get_float('ANALOG:GEN_SCALE'),
     )
     w.add_frames((p, a) for _, p, a in r.read_frames())
     h = io.BytesIO()
     w.write(h)
Пример #4
0
def save_to_c3d_file(file_path, points, fps=30):
    writer = c3d.Writer(point_rate=float(fps))
    for i in range(points.shape[1]):
        writer.add_frames([(points[:, i], np.array([[]]))])
    try:
        with open(file_path, 'wb') as file_handle:
            with warnings.catch_warnings():
                warnings.simplefilter(
                    "ignore"
                )  # ignore UserWarning: missing parameter ANALOG:DESCRIPTIONS/LABELS
                writer.write(file_handle)
    except IOError as e:
        print("Failed to write file. Reason:", e)
Пример #5
0
    def test_add_frames(self):
        r = c3d.Reader(Zipload._get('sample08.zip', 'TESTDPI.c3d'))
        w = c3d.Writer(
            point_rate=r.point_rate,
            analog_rate=r.analog_rate,
            point_scale=r.point_scale,
        )
        w.add_frames([(p, a) for _, p, a in r.read_frames()])
        w.add_frames([(p, a) for _, p, a in r.read_frames()], index=5)

        h = io.BytesIO()
        w.set_point_labels(r.point_labels)
        w.set_analog_labels(r.analog_labels)
        w.set_analog_general_scale(r.get('ANALOG:GEN_SCALE').float_value)
        w.write(h)
Пример #6
0
    def write(self, path_to_write, matrix, additional_matrix=None):
        assert np.ndim(matrix) == 3
        assert matrix.shape[2] == 3 and matrix.shape[1] == self.points_amount

        if additional_matrix == None:
            # define last two columns in the matrix of coordinates with zeros
            additional_matrix = np.zeros(dtype="float32",
                                         shape=(matrix.shape[0],
                                                self.points_amount, 2))

        writer = c3d.Writer()
        # frames - generator of tuples (coord_matrix,  analog)
        frames = ((np.concatenate((matrix[i]*-1, additional_matrix[i]), axis=1), np.array([[]]))\
                  for i in range(len(matrix)))
        writer.add_frames(frames)

        with open(path_to_write, 'wb') as h:
            writer.write(h)
Пример #7
0
import numpy as np
import json
import argparse

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='convert .json to .c3d')
    parser.add_argument('points_file', help='the json file')
    parser.add_argument('output_c3d', help='the ouput c3d file')

    args = parser.parse_args()

    with open(args.points_file, 'r') as handle:
        points_from_all_frames = json.load(handle)

    writer = c3d.Writer(point_labels=points_from_all_frames['label_names'])

    analog = np.array([])

    for frame in points_from_all_frames['Frames']:
        points_list = []
        for label in points_from_all_frames['label_names']:
            points_list.append(frame[label])

        points = np.array(points_list)
        writer.add_frames([(points, analog)])

    with open(args.output_c3d, 'wb') as handle:
        writer.write(handle)

#import c3d
Пример #8
0
import numpy as np
try:
    import c3d
except ModuleNotFoundError:
    # Force load package with no instalation
    import sys
    import os
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..\\'))
    import c3d

# Writes 100 frames recorded at 200 Hz.
# Each frame contains recordings for 24 coordinate markers.
writer = c3d.Writer(point_rate=200)
for _ in range(100):
    writer.add_frames((np.random.randn(24, 5), ()))

writer.set_point_labels([
    'RFT1', 'RFT2', 'RFT3', 'RFT4', 'LFT1', 'LFT2', 'LFT3', 'LFT4', 'RSK1',
    'RSK2', 'RSK3', 'RSK4', 'LSK1', 'LSK2', 'LSK3', 'LSK4', 'RTH1', 'RTH2',
    'RTH3', 'RTH4', 'LTH1', 'LTH2', 'LTH3', 'LTH4'
])
writer.set_analog_labels(None)

with open('random-points.c3d', 'wb') as h:
    writer.write(h)
Пример #9
0
import c3d
import numpy as np
import random

file = '/media/papachristo/My Passport/finalp/MyQualysis/output/curr/S03P1.npy'
data = np.load(file)

ds = data.shape

j = np.random.randn(30, 5)
print(j.shape)

writer = c3d.Writer()

# frame = []
for a in range(ds[0]):
    for f in range(ds[2]):
        frame = []
        for j in range(ds[3]):
            x = data[a][0][f][j][0]
            y = data[a][2][f][j][0]
            z = data[a][1][f][j][0]
            frame.append(
                [[x, y, z,
                  random.uniform(-1, 5),
                  random.uniform(-1, 5)],
                 np.asarray([])])
        # print(np.asarray(frame).shape)
        writer.add_frames(np.asarray(frame))

with open(