Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRAMES parameter is not an INT #351

Closed
Jack-Development opened this issue Dec 5, 2024 · 9 comments
Closed

FRAMES parameter is not an INT #351

Jack-Development opened this issue Dec 5, 2024 · 9 comments

Comments

@Jack-Development
Copy link

When running the file with a file-path input, it is unable to load the file with the error of "ValueError: FRAMES parameter is not an INT"

Works:

import ezc3d
c3d = ezc3d.c3d()

Doesn't Work:

import ezc3d
c3d = ezc3d.c3d("test.c3d")

Here is the exception log:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    c3d = ezc3d.c3d("test.c3d")
  File "/home/------/miniconda3/envs/002/lib/python3.8/site-packages/ezc3d/__init__.py", line 128, in __init__
    self.c3d_swig = ezc3d.c3d(path, ignore_bad_formatting)
  File "/home/------/miniconda3/envs/002/lib/python3.8/site-packages/ezc3d/ezc3d.py", line 1901, in __init__
    _ezc3d.c3d_swiginit(self, _ezc3d.new_c3d(*args))
ValueError: FRAMES parameter is not an INT

Wondered if you had any ideas on what was causing this, as it seems to work fine for everyone else?

@pariterre
Copy link
Member

Dear @Jack-Development
This is a safe-guard I added at some point since FRAMES are not allowed to be floating points number. This is actually useful for some assumption the C3D makes. In that regard, the C3D documentation confirms this should be an INT.

I suspect that you are using a C3D which was constructed by some company I did not have a C3D file from to perform test. I could make a patch, but I would need an actual C3D file. If it is okay for you, you can send one to me via mail.

That said, the FRAME must be an integer even though they decided to store it as a floating point, otherwise this c3d will be ill-formed.

@Jack-Development
Copy link
Author

Hi @pariterre
I have sent an example of the c3d file type we are using to your gmail address.
Please let me know if you have received it.

@pariterre
Copy link
Member

Dear @Jack-Development

I forgot earlier, but the problem you refer to was actually already patch. As a result, the file you sent me open just fine on my computer.

What version of ezc3d are you using? The current version is 1.5.17. I suggest to update if it is not already done :)

@Jack-Development
Copy link
Author

Hi @pariterre
I understand. I am using it alongside mmMesh, and as such am limited to Python 3.8.20, and as such am limited to 1.4.8.

Running it without the conda environment, I am able to load the c3d, but am given an incorrect frame length of 39 frames, as opposed to the 72,500+ frames and an error of "c3d['parameters']['POINT']['LABELSX']' must have the same length as nPoints of the data."

Do you have any idea of the root cause of this? I am attempting to crop the video between two frames, do you have any example scripts for this?

@Jack-Development
Copy link
Author

Hi @pariterre
I am trying to run the cropping code from other examples, writing out the following script:

def crop_c3d(file_path, start_frame, end_frame):
    # Read the c3d file
    c3d = ezc3d.c3d(file_path)

    c3d["data"]["points"] = c3d["data"]["points"][:, :, start_frame:end_frame + 1]
    del c3d["data"]["meta_points"]  # Let ezc3d do the job for the meta_points

    c3d["header"]["points"]["first_frame"] = start_frame
    c3d["header"]["points"]["last_frame"] = end_frame

    c3d["parameters"]["ANALOG"]["UNITS"]["value"] = []

    # Save the modified file with "_cropped" added to the original file name
    base, ext = os.path.splitext(file_path)
    new_file_path = f"{base}_cropped{ext}"
    c3d.write(new_file_path)


if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python crop_c3d.py <file_path> <start_frame> <end_frame>")
        sys.exit(1)

    file_path = sys.argv[1]
    start_frame = int(sys.argv[2])
    end_frame = int(sys.argv[3])

    crop_c3d(file_path, start_frame, end_frame)

However, upon attempting to load the c3d file and check the length:

def get_frame_length(c3d_file_path):
    print("Loading file " + c3d_file_path)
    c3d = ezc3d.c3d(c3d_file_path)
    print("C3D file loaded.")
    frame_length = c3d['header']['points']['last_frame'] - c3d['header']['points']['first_frame'] + 1
    print("Frame length calculated.")
    return frame_length


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python test_c3d.py <c3d_file_path>")
        sys.exit(1)

    c3d_file_path = sys.argv[1]
    frame_length = get_frame_length(c3d_file_path)
    print(f"Frame length: {frame_length}")

I am getting a Segmentation Fault, even when the file is not even modified and just saved, it is unable to be loaded again by the ezc3d library, simply showing as a Segmentation Fault.

def crop_c3d(file_path, start_frame, end_frame):
    # Read the c3d file
    c3d = ezc3d.c3d(file_path)

    base, ext = os.path.splitext(file_path)
    new_file_path = f"{base}_cropped{ext}"
    c3d.write(new_file_path)
    return

@pariterre
Copy link
Member

Hi @Jack-Development
I just pushed a fixed (#352) for the reported bug

@pariterre
Copy link
Member

The updated version was pushed to PyPI, please confirm your C3D can properly be read :)

@pariterre
Copy link
Member

@Jack-Development
up :)

@Jack-Development
Copy link
Author

@pariterre
It seems to be able to load and read the markers for the c3d data now, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants