Tracking/tracking.py
def process(self):
        """
            dlc analyze_video for each video file with the correct dlc model
            rename and move .h5 and .pickle file to the pose_file folder
        """
        def move_video(complete_path, move_video_path):
            print('Moving video over')
            try:
                shutil.copy(complete_path, move_video_path)
            except:
                raise FileNotFoundError('Could not move {} to {}'.format(complete_path, move_video_path))
            else:
                print('     file moved correctly')


        for i, video in enumerate(self.video_to_process):
            print('Processing video {} of {}'.format(i+1, len(self.video_to_process)))

            # Get the DLC model config path
            config_path = os.path.join(self.nets_folder, self.dlc_proj_name)
                
            # Move video to local HD: otherwise analysis breaks if internet connection is unstable
            complete_path = os.path.join(self.video_folder, video)

            if not os.path.isfile(complete_path): 
                print("!!! could not find file: ", complete_path)
                continue
            
            if os.path.getsize(complete_path) < 2000: continue # Check that video has frames
            
            if self.move_video:
                move_video_path = os.path.join(self.temp_fld, video)
                if os.path.isfile(move_video_path):
                    # Video already there, but is it complete
                    if not os.path.getsize(move_video_path) == os.path.getsize(complete_path):
                        # Nope, move it 
                        os.remove(move_video_path)
                        move_video(complete_path, move_video_path)
                else:
                    move_video(complete_path, move_video_path)
                
                # Check that moving video worked correctly
                if not os.path.getsize(complete_path) == os.path.getsize(move_video_path): raise ValueError('Smth went wrong while moving the video')

                # store the path on the moved video so that we can delete it at the end of the processing
                self.move_video_path = move_video_path
            try:
                cap = cv2.VideoCapture(move_video_path)
                if not cap.isOpened(): raise ValueError
            except: 
                print("The video was not moved, analysing the orignal on winstore")
                cap = cv2.VideoCapture(complete_path)
                if not cap.isOpened(): 
                    raise ValueError('Original video file might be corrupted', complete_path)
                move_video_path = complete_path # copy variable to be used below

            # Run DLC analysis
            print("""
            Video:  {}
            Config: {}
            
            """.format(move_video_path, config_path))


            analyze_videos(config_path, [move_video_path], gputouse=0, save_as_csv=False)
            filterpredictions(config_path, [move_video_path], videotype="mp4", save_as_csv=False, filtertype='median')

            # Rename and move .h5 and .pickle
            analysis_output = [f for f in os.listdir(self.temp_fld) if 'filtered.h5' in f]


            for f in analysis_output:
                origin = os.path.join(self.temp_fld, f)
                name, ext = f.split('.')
                correct_name = f.split('DLC')[0]+'_pose'
                dest = os.path.join(self.pose_folder, correct_name+'.'+ext)
                try:
                    shutil.move(origin, dest)
                except:
                    raise FileExistsError('Could not move pose file from {} to {}'.format(origin, dest))

            # Remove video file moved to local harddrive
            # os.remove(move_video_path)

            # All done, on to the next

            dlc analyze_video for each video file with the correct dlc model
            rename and move .h5 and .pickle file to the pose_file folder
        
dlc analyze_video for each video file with the correct dlc model
rename and move .h5 and .pickle file to the pose_file folder
dlc analyze_video for each video file with the correct dlc model rename and move . h5 and . pickle file to the pose_file folder
def process(self):
        def move_video(complete_path, move_video_path):
            print('Moving video over')
            try:
                shutil.copy(complete_path, move_video_path)
            except:
                raise FileNotFoundError('Could not move {} to {}'.format(complete_path, move_video_path))
            else:
                print('     file moved correctly')
        for i, video in enumerate(self.video_to_process):
            print('Processing video {} of {}'.format(i+1, len(self.video_to_process)))
            config_path = os.path.join(self.nets_folder, self.dlc_proj_name)
            complete_path = os.path.join(self.video_folder, video)
            if not os.path.isfile(complete_path): 
                print("!!! could not find file: ", complete_path)
                continue
            if os.path.getsize(complete_path) < 2000: continue 
            if self.move_video:
                move_video_path = os.path.join(self.temp_fld, video)
                if os.path.isfile(move_video_path):
                    if not os.path.getsize(move_video_path) == os.path.getsize(complete_path):
                        os.remove(move_video_path)
                        move_video(complete_path, move_video_path)
                else:
                    move_video(complete_path, move_video_path)
                if not os.path.getsize(complete_path) == os.path.getsize(move_video_path): raise ValueError('Smth went wrong while moving the video')
                self.move_video_path = move_video_path
            try:
                cap = cv2.VideoCapture(move_video_path)
                if not cap.isOpened(): raise ValueError
            except: 
                print("The video was not moved, analysing the orignal on winstore")
                cap = cv2.VideoCapture(complete_path)
                if not cap.isOpened(): 
                    raise ValueError('Original video file might be corrupted', complete_path)
                move_video_path = complete_path 
            print("""
            Video:  {}
            Config: {}
            """.format(move_video_path, config_path))
            analyze_videos(config_path, [move_video_path], gputouse=0, save_as_csv=False)
            filterpredictions(config_path, [move_video_path], videotype="mp4", save_as_csv=False, filtertype='median')
            analysis_output = [f for f in os.listdir(self.temp_fld) if 'filtered.h5' in f]
            for f in analysis_output:
                origin = os.path.join(self.temp_fld, f)
                name, ext = f.split('.')
                correct_name = f.split('DLC')[0]+'_pose'
                dest = os.path.join(self.pose_folder, correct_name+'.'+ext)
                try:
                    shutil.move(origin, dest)
                except:
                    raise FileExistsError('Could not move pose file from {} to {}'.format(origin, dest))
def process ( self ) : def move_video ( complete_path , move_video_path ) : print ( 'Moving video over' ) try : shutil . copy ( complete_path , move_video_path ) except : raise FileNotFoundError ( 'Could not move {} to {}' . format ( complete_path , move_video_path ) ) else : print ( '     file moved correctly' ) for i , video in enumerate ( self . video_to_process ) : print ( 'Processing video {} of {}' . format ( i + 1 , len ( self . video_to_process ) ) ) config_path = os . path . join ( self . nets_folder , self . dlc_proj_name ) complete_path = os . path . join ( self . video_folder , video ) if not os . path . isfile ( complete_path ) : print ( "!!! could not find file: " , complete_path ) continue if os . path . getsize ( complete_path ) < 2000 : continue if self . move_video : move_video_path = os . path . join ( self . temp_fld , video ) if os . path . isfile ( move_video_path ) : if not os . path . getsize ( move_video_path ) == os . path . getsize ( complete_path ) : os . remove ( move_video_path ) move_video ( complete_path , move_video_path ) else : move_video ( complete_path , move_video_path ) if not os . path . getsize ( complete_path ) == os . path . getsize ( move_video_path ) : raise ValueError ( 'Smth went wrong while moving the video' ) self . move_video_path = move_video_path try : cap = cv2 . VideoCapture ( move_video_path ) if not cap . isOpened ( ) : raise ValueError except : print ( "The video was not moved, analysing the orignal on winstore" ) cap = cv2 . VideoCapture ( complete_path ) if not cap . isOpened ( ) : raise ValueError ( 'Original video file might be corrupted' , complete_path ) move_video_path = complete_path print ( """
            Video:  {}
            Config: {}
            
            """ . format ( move_video_path , config_path ) ) analyze_videos ( config_path , [ move_video_path ] , gputouse = 0 , save_as_csv = False ) filterpredictions ( config_path , [ move_video_path ] , videotype = "mp4" , save_as_csv = False , filtertype = 'median' ) analysis_output = [ f for f in os . listdir ( self . temp_fld ) if 'filtered.h5' in f ] for f in analysis_output : origin = os . path . join ( self . temp_fld , f ) name , ext = f . split ( '.' ) correct_name = f . split ( 'DLC' ) [ 0 ] + '_pose' dest = os . path . join ( self . pose_folder , correct_name + '.' + ext ) try : shutil . move ( origin , dest ) except : raise FileExistsError ( 'Could not move pose file from {} to {}' . format ( origin , dest ) )
dlc analyze_video for each video file with the correct dlc model
rename and move .h5 and .pickle file to the pose_file folder
dlc analyze_video for each video file with the correct dlc model rename and move . h5 and . pickle file to the pose_file folder
"""
            dlc analyze_video for each video file with the correct dlc model
            rename and move .h5 and .pickle file to the pose_file folder
        """ # Get the DLC model config path # Move video to local HD: otherwise analysis breaks if internet connection is unstable # Check that video has frames # Video already there, but is it complete # Nope, move it  # Check that moving video worked correctly # store the path on the moved video so that we can delete it at the end of the processing # copy variable to be used below # Run DLC analysis # Rename and move .h5 and .pickle # Remove video file moved to local harddrive # os.remove(move_video_path) # All done, on to the next
self