Skip to content
Merged
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
16 changes: 14 additions & 2 deletions deeplabcut/utils/make_labeled_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pathlib import Path
from functools import partial
from multiprocessing import Pool, get_start_method
from typing import Iterable, Callable, Optional, Union
from typing import Iterable, Callable, List, Optional, Union

import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -1009,6 +1009,7 @@ def create_video_with_all_detections(
shuffle=1,
trainingsetindex=0,
displayedbodyparts="all",
cropping: Optional[List[int]] = None,
destfolder=None,
modelprefix="",
confidence_to_alpha: Union[bool, Callable[[float], float]] = False,
Expand Down Expand Up @@ -1040,6 +1041,9 @@ def create_video_with_all_detections(
from config.yaml are used orr a list of strings that are a subset of the full list.
E.g. ['hand','Joystick'] for the demo Reaching-Mackenzie-2018-08-30/config.yaml to select only these two body parts.

cropping: list[int], optional (default=None)
If passed in, the [x1, x2, y1, y2] crop coordinates are used to shift detections appropriately.

destfolder: string, optional
Specifies the destination folder that was used for storing analysis data (default is the path of the video).

Expand Down Expand Up @@ -1081,7 +1085,8 @@ def create_video_with_all_detections(
)

if not (os.path.isfile(outputname)):
print("Creating labeled video for ", str(Path(video).stem))
video_name = str(Path(video).stem)
print("Creating labeled video for ", video_name)
h5file = full_pickle.replace("_full.pickle", ".h5")
data, _ = auxfun_multianimal.LoadFullMultiAnimalData(h5file)
data = dict(
Expand Down Expand Up @@ -1111,6 +1116,11 @@ def create_video_with_all_detections(
clip = vp(fname=video, sname=outputname, codec="mp4v")
ny, nx = clip.height(), clip.width()

x1 = 0
y1 = 0
if cropping is not None:
x1, _, y1, _ = cropping

for n in trange(clip.nframes):
frame = clip.load_frame()
if frame is None:
Expand All @@ -1122,6 +1132,8 @@ def create_video_with_all_detections(
if det.label not in bpts or det.confidence < pcutoff:
continue
x, y = det.pos
x += x1
y += y1
rr, cc = disk((y, x), dotsize, shape=(ny, nx))
alpha = 1
if confidence_to_alpha is not None:
Expand Down