cropping-related fixes in `analyze_videos` and `create_labeled_video` by deruyter92 · Pull Request #3161 · DeepLabCut/DeepLabCut

added 4 commits

December 12, 2025 14:34
Faulty conditional was evaluating whether the cropping parameter in config equals string "True", rather than boolean True. This lead to unintended false evaluation for cropping field with boolean value True.
In the original behaviour, cropping=None was interpreted as read cropping params from config. This is in contrast to most other occurrences (`video_inference`, `gui.tabs.analyze_videos`, `VideoIterator`), which interpret cropping=None as no cropping. This leads to potential conflicts.

This commit changes the behaviour for cropping=None, which is now interpreted as no cropping (like elsewhere).

For backwards compatibility, the default argument is changed to 'from_config' which follows prior behavior.
Bounding box positions were corrected by the crop margin, even when the output video is also cropped (which should not be the case). This leads to misplaced bounding boxes.

This commit fixes the unintended behaviour where bounding box positions are always corrected: i.e. bounding boxes are only corrected when cropping was used during video AND the output video is not cropped.
In prior implementation, whether to use cropping or not was determined by the cropping coordinates, rather than the boolean cropping flag in video metadata.

When metadata specifies cropping=False, now no cropping is applied.

@deruyter92

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@deruyter92

@deruyter92

@deruyter92

…re cropped in `extract_outlier_frames`.

This commit fixes a bug that introduces a mismatch between label-coordinates and video, when extracting cropped outlier frames.

When the `analyze_videos` step was performed using a cropping window. The predicted keypoints are stored in the crop-window space. In the previous implementation, the keypoints are ALWAYS converted back to reflect full-video coordinates by adding the left and top crop margins (introduced in PR DeepLabCut#2538). However the keypoints should only be converted back if the output frames are full-video, not when they are cropped. This commit fixes that by using the difference between the output margin and the margin stored in metadata.
…refactor_labeled_video_creation

@deruyter92

@deruyter92

@deruyter92