MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / CreateVideo

Function CreateVideo

deeplabcut/utils/make_labeled_video.py:74–218  ·  view source on GitHub ↗

Creating individual frames with labeled body parts and making a video.

(
    clip,
    Dataframe,
    pcutoff,
    dotsize,
    colormap,
    bodyparts2plot,
    trailpoints,
    cropping,
    x1,
    x2,
    y1,
    y2,
    bodyparts2connect,
    skeleton_color,
    draw_skeleton,
    displaycropped,
    color_by,
    confidence_to_alpha=None,
    plot_bboxes=True,
    bboxes_list=None,
    bboxes_pcutoff=0.6,
    bboxes_color: tuple | None = None,
)

Source from the content-addressed store, hash-verified

72
73
74def CreateVideo(
75 clip,
76 Dataframe,
77 pcutoff,
78 dotsize,
79 colormap,
80 bodyparts2plot,
81 trailpoints,
82 cropping,
83 x1,
84 x2,
85 y1,
86 y2,
87 bodyparts2connect,
88 skeleton_color,
89 draw_skeleton,
90 displaycropped,
91 color_by,
92 confidence_to_alpha=None,
93 plot_bboxes=True,
94 bboxes_list=None,
95 bboxes_pcutoff=0.6,
96 bboxes_color: tuple | None = None,
97):
98 """Creating individual frames with labeled body parts and making a video."""
99 bpts = Dataframe.columns.get_level_values("bodyparts")
100 all_bpts = bpts.values[::3]
101 if draw_skeleton:
102 color_for_skeleton = (np.array(mcolors.to_rgba(skeleton_color))[:3] * 255).astype(np.uint8)
103 # recode the bodyparts2connect into indices for df_x and df_y for speed
104 bpts2connect = get_segment_indices(bodyparts2connect, all_bpts)
105
106 if displaycropped:
107 ny, nx = y2 - y1, x2 - x1
108 else:
109 ny, nx = clip.height(), clip.width()
110
111 fps = clip.fps()
112 if isinstance(fps, float):
113 if fps * 1000 > 65535:
114 fps = round(fps)
115 nframes = clip.nframes
116 duration = nframes / fps
117
118 print(f"Duration of video [s]: {round(duration, 2)}, recorded with {round(fps, 2)} fps!")
119 print(f"Overall # of frames: {nframes} with cropped frame dimensions: {nx} {ny}")
120 print("Generating frames and creating video.")
121
122 df_x, df_y, df_likelihood = Dataframe.values.reshape((len(Dataframe), -1, 3)).T
123
124 if cropping and not displaycropped:
125 df_x += x1
126 df_y += y1
127 colorclass = plt.cm.ScalarMappable(cmap=colormap)
128
129 bplist = bpts.unique().to_list()
130 nbodyparts = len(bplist)
131 if Dataframe.columns.nlevels == 3:

Callers 1

create_videoFunction · 0.85

Calls 9

get_segment_indicesFunction · 0.85
uniqueMethod · 0.80
load_frameMethod · 0.80
heightMethod · 0.45
widthMethod · 0.45
fpsMethod · 0.45
getMethod · 0.45
save_frameMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected