deeplabcut.utils.make_labeled_video
DeepLabCut2.0 Toolbox (deeplabcut.org) © A. & M. Mathis Labs https://github.com/DeepLabCut/DeepLabCut Please see AUTHORS for contributors.
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS Licensed under GNU Lesser General Public License v3.0
Hao Wu, hwu01@g.harvard.edu contributed the original OpenCV class. Thanks! You can find the directory for your ffmpeg bindings by: "find / | grep ffmpeg" and then setting it.
Functions:
| Name | Description |
|---|---|
CreateVideo |
Creating individual frames with labeled body parts and making a video. |
CreateVideoSlow |
Creating individual frames with labeled body parts and making a video. |
create_labeled_video |
Labels the bodyparts in a video. |
create_video_with_all_detections |
Create a video labeled with all the detections stored in a '*_full.pickle' file. |
proc_video |
Helper function for create_videos. |
CreateVideo
CreateVideo(
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,
)
Creating individual frames with labeled body parts and making a video.
Source code in deeplabcut/utils/make_labeled_video.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
CreateVideoSlow
CreateVideoSlow(
videooutname,
clip,
Dataframe,
tmpfolder,
dotsize,
colormap,
alphavalue,
pcutoff,
trailpoints,
cropping,
x1,
x2,
y1,
y2,
save_frames,
bodyparts2plot,
outputframerate,
Frames2plot,
bodyparts2connect,
skeleton_color,
draw_skeleton,
displaycropped,
color_by,
plot_bboxes=True,
bboxes_list=None,
bboxes_pcutoff=0.6,
bboxes_color: str | None = None,
)
Creating individual frames with labeled body parts and making a video.
Source code in deeplabcut/utils/make_labeled_video.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
create_labeled_video
create_labeled_video(
config: str,
videos: list[str],
video_extensions: str | Sequence[str] | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
filtered: bool = False,
fastmode: bool = True,
save_frames: bool = False,
keypoints_only: bool = False,
Frames2plot: list[int] | None = None,
displayedbodyparts: list[str] | str = "all",
displayedindividuals: list[str] | str = "all",
codec: str = "mp4v",
outputframerate: int | None = None,
destfolder: Path | str | None = None,
draw_skeleton: bool = False,
trailpoints: int = 0,
displaycropped: bool = False,
color_by: str = "bodypart",
modelprefix: str = "",
init_weights: str = "",
track_method: str = "",
superanimal_name: str = "",
pcutoff: float | None = None,
skeleton: list = None,
skeleton_color: str = "white",
dotsize: int = 8,
colormap: str = "rainbow",
alphavalue: float = 0.5,
overwrite: bool = False,
confidence_to_alpha: bool | Callable[[float], float] = False,
plot_bboxes: bool = True,
bboxes_pcutoff: float | None = None,
max_workers: int | None = None,
**kwargs
)
Labels the bodyparts in a video.
Make sure the video is already analyzed by the function
deeplabcut.analyze_videos.
Parameters
config : string Full path of the config.yaml file.
list[str]
A list of strings containing the full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored.
str | Sequence[str] | None, optional, default=None
Controls how videos are filtered, based on file extension.
File paths and directory contents are treated differently:
- None (default): file paths are accepted as-is; directories are
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional, default=1
Number of shuffles of training dataset.
int, optional, default=0
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml.
bool, optional, default=False
Boolean variable indicating if filtered output should be plotted rather than
frame-by-frame predictions. Filtered version can be calculated with
deeplabcut.filterpredictions.
bool, optional, default=True
If True, uses openCV (much faster but less customization of video) instead
of matplotlib if False. You can also "save_frames" individually or not in
the matplotlib mode (if you set the "save_frames" variable accordingly).
However, using matplotlib to create the frames it therefore allows much more
flexible (one can set transparency of markers, crop, and easily customize).
bool, optional, default=False
If True, creates each frame individual and then combines into a video.
Setting this to True is relatively slow as it stores all individual frames.
bool, optional, default=False
By default, both video frames and keypoints are visible. If True, only the
keypoints are shown. These clips are an hommage to Johansson movies,
see https://www.youtube.com/watch?v=1F5ICP9SYLU and of course his seminal
paper: "Visual perception of biological motion and a model for its analysis"
by Gunnar Johansson in Perception & Psychophysics 1973.
List[int] or None, optional, default=None
If not None and save_frames=True then the frames corresponding to the
index will be plotted. For example, Frames2plot=[0,11] will plot the first
and the 12th frame.
list[str] or str, optional, default="all"
This selects the body parts that are plotted in the video. If all, then all
body parts from config.yaml are used. If 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 body parts.
list[str] or str, optional, default="all"
Individuals plotted in the video. By default, all individuals present in the config will be shown.
str, optional, default="mp4v"
Codec for labeled video. For available options, see http://www.fourcc.org/codecs.php. Note that this depends on your ffmpeg installation.
int or None, optional, default=None
Positive number, output frame rate for labeled video (only available for the
mode with saving frames.) If None, which results in the original video
rate.
Path, string or None, optional, default=None
Specifies the destination folder that was used for storing analysis data. If
None, the path of the video file is used.
bool, optional, default=False
If True adds a line connecting the body parts making a skeleton on each
frame. The body parts to be connected and the color of these connecting lines
are specified in the config file.
int, optional, default=0
Number of previous frames whose body parts are plotted in a frame (for displaying history).
bool, optional, default=False
Specifies whether only cropped frame is displayed (with labels analyzed therein), or the original frame with the labels analyzed in the cropped subset.
string, optional, default='bodypart'
Coloring rule. By default, each bodypart is colored differently. If set to 'individual', points belonging to a single individual are colored the same.
str, optional, default=""
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder.
str,
Checkpoint path to the super model
string, optional, default=""
Specifies the tracker used to generate the data. Empty by default (corresponding to a single animal project). For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will be taken from the config.yaml file if none is given.
str, optional, default=""
Name of the superanimal model.
float, optional, default=None
Overrides the pcutoff set in the project configuration to plot the trajectories.
skeleton: list, optional, default=[],
string, optional, default="white",
Color for the skeleton
dotsize, int, optional, default=8, Size of label dots tu use
str, optional, default="rainbow",
Colormap to use for the labels
alphavalue: float, optional, default=0.5,
bool, optional, default=False
If True overwrites existing labeled videos.
Union[bool, Callable[[float], float], default=False
If False, all keypoints will be plot with alpha=1. Otherwise, this can be defined as a function f: [0, 1] -> [0, 1] such that the alpha value for a keypoint will be set as a function of its score: alpha = f(score). The default function used when True is f(x) = max(0, (x - pcutoff)/(1 - pcutoff)).
bool, optional, default=True
If using Pytorch and in Top-Down mode, setting this to true will also plot the bounding boxes
bboxes_pcutoff, float, optional, default=None: If plotting bounding boxes, this overrides the bboxes_pcutoff set in the model configuration.
max_workers (int | None): Maximum number of processes to use for multiprocessing. Set this parameter to limit the total RAM-usage of simultaneous processes. Default: no maximum (i.e. number of spawned processes is based on the number of cores and the number of input videos).
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
results : list[bool]
``True`` if the video is successfully created for each item in ``videos``.
Examples
Create the labeled video for a single video
deeplabcut.create_labeled_video( '/analysis/project/reaching-task/config.yaml', ['/analysis/project/videos/reachingvideo1.avi'], )
Create the labeled video for a single video and store the individual frames
deeplabcut.create_labeled_video( '/analysis/project/reaching-task/config.yaml', ['/analysis/project/videos/reachingvideo1.avi'], fastmode=True, save_frames=True, )
Create the labeled video for multiple videos
deeplabcut.create_labeled_video( '/analysis/project/reaching-task/config.yaml', [ '/analysis/project/videos/reachingvideo1.avi', '/analysis/project/videos/reachingvideo2.avi', ], )
Create the labeled video for all the videos with an .avi extension in a directory.
deeplabcut.create_labeled_video( '/analysis/project/reaching-task/config.yaml', ['/analysis/project/videos/'], )
Create the labeled video for all the videos with an .mp4 extension in a directory.
deeplabcut.create_labeled_video( '/analysis/project/reaching-task/config.yaml', ['/analysis/project/videos/'], video_extensions='mp4', )
Source code in deeplabcut/utils/make_labeled_video.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | |
create_video_with_all_detections
create_video_with_all_detections(
config,
videos,
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
displayedbodyparts="all",
cropping: list[int] | None = None,
destfolder=None,
modelprefix="",
confidence_to_alpha: bool | Callable[[float], float] = False,
plot_bboxes: bool = True,
**kwargs
)
Create a video labeled with all the detections stored in a '*_full.pickle' file.
Parameters
config : str Absolute path to the config.yaml file
list of str
A list of strings containing the full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored.
str | Sequence[str] | None, optional, default=None
Controls how videos are filtered, based on file extension.
File paths and directory contents are treated differently:
- None (default): file paths are accepted as-is; directories are
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional
Number of shuffles of training dataset. Default is set to 1.
int, optional
Integer specifying which TrainingsetFraction to use. By default the first (note that TrainingFraction is a list in config.yaml).
list of strings, optional
This selects the body parts that are plotted in the video.
Either all, then all body parts from config.yaml are used or
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.
list[int], optional (default=None)
If passed in, the [x1, x2, y1, y2] crop coordinates are used to shift detections appropriately.
string, optional
Specifies the destination folder that was used for storing analysis data (default is the path of the video).
Union[bool, Callable[[float], float], default=False
If False, all keypoints will be plot with alpha=1. Otherwise, this can be defined as a function f: [0, 1] -> [0, 1] such that the alpha value for a keypoint will be set as a function of its score: alpha = f(score). The default function used when True is f(x) = x.
bool, optional (default=True)
If detections were produced using a Pytorch Top-Down model, setting this parameter to True will also plot the bounding boxes generated by the detector.
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Source code in deeplabcut/utils/make_labeled_video.py
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 | |
proc_video
proc_video(
videos,
destfolder,
filtered,
DLCscorer,
DLCscorerlegacy,
track_method,
cfg,
individuals,
color_by,
bodyparts,
codec,
bodyparts2connect,
trailpoints,
save_frames,
outputframerate,
Frames2plot,
draw_skeleton,
skeleton_color,
displaycropped,
fastmode,
keypoints_only,
overwrite,
video,
init_weights="",
pcutoff: float | None = None,
confidence_to_alpha: Callable[[float], float] | None = None,
plot_bboxes: bool = True,
bboxes_pcutoff: float = 0.6,
)
Helper function for create_videos.
Parameters
Returns
result : bool
``True`` if a video is successfully created.
Source code in deeplabcut/utils/make_labeled_video.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |