DeepLabCut / DLC2NWB

Utilities to convert DeepLabCut (DLC), output to/from Neurodata Without Borders (NWB) format.
MIT License
14 stars 7 forks source link

Can't get movie timestamps due to TypeError: object of type 'cv2.VideoCapture' has no len() #22

Open johnmbarrett opened 8 months ago

johnmbarrett commented 8 months ago

It is impossible to retrieve movie timestamps due to dlc2nwb.utils.get_movietimestamps throwing TypeError: object of type 'cv2.VideoCapture' has no len()

Steps to reproduce:

Expected behaviour:

The timestamps are returned

Actual behaviour:

TypeError: object of type 'cv2.VideoCapture' has no len()

Environment info:

OS: Windows 10 x64 Conda version: 23.3.1 Python version: 3.9.0 opencv-python version: 4.7.0.72 dlc2nwb version: 0.3

Additional info:

This error might depend on the opencv-python version, in which case pinning the DLC2NWB package to whichever version added the ability to get the len() of a cv.VideoReader (or the one before they took it away if it's an old feature) is the simplest solution.

Alternatively, the first return value of reader.read() is a boolean indicating whether a frame was successfully reader, so using this to change the for loop to a while loop, like so:

success, _ = reader.read()
while success:
    timestamps.append(reader.get(cv2.CAP_PROP_POS_MSEC))
    success, _ = reader.read()

fixes the issue. However, (again, possibly depending on your opencv-python version) you then run into an AttributeError on line 83, since a cv2.VideoReader has no attribute fps. This can be fixed by replacing reader.fps on that line with reader.get(cv2.CAP_PROP_FPS)

AlexEMG commented 6 months ago

Agree, feel free to submit a PR!