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

fix video len bug #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dlc2nwb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ def get_movie_timestamps(movie_file, VARIABILITYBOUND=1000, infer_timestamps=Tru

reader = cv2.VideoCapture(movie_file)
timestamps = []
for _ in range(len(reader)):
n_frames = int(reader.get(cv2.CAP_PROP_FRAME_COUNT))
fps = reader.get(cv2.CAP_PROP_FPS)

for _ in range(n_frames):
_ = reader.read()
timestamps.append(reader.get(cv2.CAP_PROP_POS_MSEC))

timestamps = np.array(timestamps) / 1000 # Convert to seconds

if np.nanvar(np.diff(timestamps)) < 1.0 / reader.fps * 1.0 / VARIABILITYBOUND:
if np.nanvar(np.diff(timestamps)) < 1.0 / fps * 1.0 / VARIABILITYBOUND:
warnings.warn(
"Variability of timestamps suspiciously small. See: https://github.com/DeepLabCut/DLC2NWB/issues/1"
)
Expand Down Expand Up @@ -195,6 +198,7 @@ def _write_pes_to_nwbfile(
paf_graph,
timestamps,
exclude_nans,
**pose_estimation_container_kwargs,
):
pose_estimation_series = []
for kpt, xyp in df_animal.groupby(level="bodyparts", axis=1, sort=False):
Expand Down Expand Up @@ -230,6 +234,7 @@ def _write_pes_to_nwbfile(
source_software_version=deeplabcut_version,
nodes=[pes.name for pes in pose_estimation_series],
edges=paf_graph if paf_graph else None,
**pose_estimation_container_kwargs,
)
if 'behavior' in nwbfile.processing:
behavior_pm = nwbfile.processing["behavior"]
Expand Down