2020Hao Wu, hwu01@g.harvard.edu contributed the original OpenCV class. Thanks!
2121You can find the directory for your ffmpeg bindings by: "find / | grep ffmpeg" and then setting it.
2222"""
23+ from __future__ import annotations
2324
2425import argparse
2526import os
@@ -382,7 +383,7 @@ def create_labeled_video(
382383 init_weights = "" ,
383384 track_method = "" ,
384385 superanimal_name = "" ,
385- pcutoff = 0.6 ,
386+ pcutoff = None ,
386387 skeleton = [],
387388 skeleton_color = "white" ,
388389 dotsize = 8 ,
@@ -501,6 +502,9 @@ def create_labeled_video(
501502 For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will
502503 be taken from the config.yaml file if none is given.
503504
505+ pcutoff: string, optional, default=None
506+ Overrides the pcutoff set in the project configuration to plot the trajectories.
507+
504508 overwrite: bool, optional, default=False
505509 If ``True`` overwrites existing labeled videos.
506510
@@ -560,13 +564,16 @@ def create_labeled_video(
560564 )
561565 """
562566 if config == "" :
563- pass
567+ if pcutoff is None :
568+ pcutoff = 0.6
564569 else :
565570 cfg = auxiliaryfunctions .read_config (config )
566571 trainFraction = cfg ["TrainingFraction" ][trainingsetindex ]
567572 track_method = auxfun_multianimal .get_track_method (
568573 cfg , track_method = track_method
569574 )
575+ if pcutoff is None :
576+ pcutoff = cfg ["pcutoff" ]
570577
571578 if init_weights == "" :
572579 DLCscorer , DLCscorerlegacy = auxiliaryfunctions .get_scorer_name (
@@ -659,6 +666,7 @@ def create_labeled_video(
659666 keypoints_only ,
660667 overwrite ,
661668 init_weights = init_weights ,
669+ pcutoff = pcutoff ,
662670 confidence_to_alpha = confidence_to_alpha ,
663671 )
664672
@@ -699,6 +707,7 @@ def proc_video(
699707 overwrite ,
700708 video ,
701709 init_weights = "" ,
710+ pcutoff : float | None = None ,
702711 confidence_to_alpha : Optional [Callable [[float ], float ]] = None ,
703712):
704713 """Helper function for create_videos
@@ -716,6 +725,9 @@ def proc_video(
716725 if destfolder is None :
717726 destfolder = videofolder # where your folder with videos is.
718727
728+ if pcutoff is None :
729+ pcutoff = cfg ["pcutoff" ]
730+
719731 auxiliaryfunctions .attempt_to_make_folder (destfolder )
720732
721733 os .chdir (destfolder ) # THE VIDEO IS STILL IN THE VIDEO FOLDER
@@ -751,7 +763,10 @@ def proc_video(
751763 s = "_id" if color_by == "individual" else "_bp"
752764 else :
753765 s = ""
754- videooutname = filepath .replace (".h5" , f"{ s } _labeled.mp4" )
766+
767+ videooutname = filepath .replace (
768+ ".h5" , f"{ s } _p{ int (100 * pcutoff )} _labeled.mp4"
769+ )
755770 if os .path .isfile (videooutname ) and not overwrite :
756771 print ("Labeled video already created. Skipping..." )
757772 return
@@ -779,7 +794,7 @@ def proc_video(
779794 df ,
780795 videooutname ,
781796 inds ,
782- cfg [ " pcutoff" ] ,
797+ pcutoff ,
783798 cfg ["dotsize" ],
784799 cfg ["alphavalue" ],
785800 skeleton_color = skeleton_color ,
@@ -801,7 +816,7 @@ def proc_video(
801816 cfg ["dotsize" ],
802817 cfg ["colormap" ],
803818 cfg ["alphavalue" ],
804- cfg [ " pcutoff" ] ,
819+ pcutoff ,
805820 trailpoints ,
806821 cropping ,
807822 x1 ,
@@ -828,7 +843,7 @@ def proc_video(
828843 bbox = (x1 , x2 , y1 , y2 ),
829844 codec = codec ,
830845 output_path = videooutname ,
831- pcutoff = cfg [ " pcutoff" ] ,
846+ pcutoff = pcutoff ,
832847 dotsize = cfg ["dotsize" ],
833848 cmap = cfg ["colormap" ],
834849 color_by = color_by ,
0 commit comments