EmbodiedCognition / py-c3d

Read & write C3D mocap files
http://c3d.rtfd.org
MIT License
104 stars 47 forks source link

Problem writing C3D file #10

Closed haripen closed 2 years ago

haripen commented 6 years ago

Hi,

I'm trying to read, process, and write C3D files with py-c3d (0.3.0). The input C3D files are generated with the (old) Vicon Workstation software and I'm using Sypder (Python 3.6.3) on a Win 64-bit machine.

Your reading example works just fine. However, the writing examples of both the stable version as well as the read/process/write example of the latest version result in the following error

Traceback (most recent call last):

  File "<ipython-input-27-45556bdd732f>", line 9, in <module>
    writer.write(h)

  File "C:\ProgramData\Anaconda3\lib\site-packages\c3d.py", line 1046, in write
    points, analog = self._frames[0]

ValueError: too many values to unpack (expected 2)

Do you have any idea why? Thanks in advance!

juan-cardelino commented 6 years ago

I'm having exactly the same issue with c3d files downloaded from Carneggie Mellon University

OlafHaag commented 6 years ago

I was facing the same issue, but after a lot of tinkering, I got it to work. Let a point be a ndarray with 3 columns for x,y,z and each row is a frame. First I appended the columns for conditionals and number of cameras observing the point (all zeros). point = np.hstack((point, np.zeros((point.shape[0], 2), dtype=point.dtype))) I then appended the point to a list of points and converted the list to an array. There's probably a better way for this. The frames to add need to be a sequence of tuples. The points need to have 3 dimensions (point x frame x axis), the analogs 2.

points.append(point)
points = np.array(points)
writer = c3d.Writer()
for i in range(points.shape[1]):  # for each frame
    writer.add_frames([(points[:, i], np.array([[]]))])  # empty 2 dimensional ndarray for analogs
with open('test.c3d', 'wb') as h:
    writer.write(h)
juan-cardelino commented 6 years ago

Actually I've made a mistake with my comment, I was having problems reading the Carneggie Mellon examples. But I will try with a modification of your example

ricardoilla commented 3 years ago

I was facing the same issue, but after a lot of tinkering, I got it to work. Let a point be a ndarray with 3 columns for x,y,z and each row is a frame. First I appended the columns for conditionals and number of cameras observing the point (all zeros). point = np.hstack((point, np.zeros((point.shape[0], 2), dtype=point.dtype))) I then appended the point to a list of points and converted the list to an array. There's probably a better way for this. The frames to add need to be a sequence of tuples. The points need to have 3 dimensions (point x frame x axis), the analogs 2.

points.append(point)
points = np.array(points)
writer = c3d.Writer()
for i in range(points.shape[1]):  # for each frame
    writer.add_frames([(points[:, i], np.array([[]]))])  # empty 2 dimensional ndarray for analogs
with open('test.c3d', 'wb') as h:
    writer.write(h)

Thank you!

AKuederle commented 2 years ago

Given that the workaraound seems to work, I will close the issue for now. Feel free to reopen, if you think there needs to be further discussions or work