Ejemplo n.º 1
0
def step4C_triangulate(config3d, result,session, **kwargs):
    clip_folder = os.path.join(kwargs['videos_clipped'], result)
    dlcout2d_folder = os.path.join(kwargs['video_dlcout_2D'], result)
    videos_3Dtemp = os.path.join(kwargs['videos_3Dtemp'], result)

    #os.makedirs(videos_3Dtemp, exist_ok=True)

    clip_files = os.listdir(clip_folder)
    dlcout2d_files = os.listdir(dlcout2d_folder)

    for file_name in dlcout2d_files:
        full_file_name = os.path.join(dlcout2d_folder, file_name)
        if os.path.isfile(full_file_name):
            #print("Copy {} to {}".format(full_file_name, clip_folder))
            shutil.copy(full_file_name, clip_folder)

    triangulate_outfolder = os.path.join(kwargs['video_dlcout_3D'], result)
    os.makedirs(triangulate_outfolder, exist_ok=True)
    deeplabcut.triangulate(config3d, os.path.abspath(clip_folder), videotype='.mp4', save_as_csv=True)
                           #destfolder=triangulate_outfolder)

    new_clip_files = os.listdir(clip_folder)
    for file_name in new_clip_files:
        full_file_name = os.path.join(clip_folder, file_name)
        #print("checking file:{}".format(full_file_name))
        #if file_name in clip_files:
        if file_name.endswith(kwargs['output_ext']):
            print("")
            #print("stay in clip folder:{}".format(file_name))
        elif "DLC_3D" in file_name:
            #print("move to 3D dlcout folder:{} and then delete it:{}".format(triangulate_outfolder,file_name))
            shutil.copy(full_file_name, triangulate_outfolder)
            os.remove(full_file_name)
        elif not ("DLC_3D" in file_name or file_name.endswith(kwargs['output_ext'])):
            #print("move to 2D dlcout folder:{} and then delete it:{}".format(dlcout2d_folder,file_name))
            #target_file_name = os.path.join(dlcout2d_folder, file_name)
            shutil.copy(full_file_name, dlcout2d_folder)
            os.remove(full_file_name)
        else:
            print("unexpected file:{}".format(full_file_name))
            #os.remove(full_file_name)

    print('triangulation done.')
Ejemplo n.º 2
0
for idx, name in enumerate(cam2_images):
    os.rename(
        name,
        os.path.join(cwd,
                     str("camera-2_" + "{0:0=2d}".format(idx + 1) + ".jpg")))

# Removing some of the images where the corner was not detected
[os.remove(file) for file in glob.glob(os.path.join(cwd, "*06.jpg"))]
[os.remove(file) for file in glob.glob(os.path.join(cwd, "*01.jpg"))]

print("CALIBRATING THE CAMERAS")
deeplabcut.calibrate_cameras(path_config_file, calibrate=True)

print("CHECKING FOR UNDISTORTION")
deeplabcut.check_undistortion(path_config_file)

print("TRIANGULATING")
video_dir = os.path.join(basepath, folder)
deeplabcut.triangulate(path_config_file, video_dir, save_as_csv=True)

print("CREATING LABELED VIDEO 3-D")
deeplabcut.create_labeled_video_3d(path_config_file, [video_dir],
                                   start=5,
                                   end=10)

# output_path = [os.path.join(basepath,folder)]
# deeplabcut.create_labeled_video_3d(path_config_file,output_path,start=5,end=10)

print("ALL DONE!!! - default 3D cases are functional.")
Ejemplo n.º 3
0
        os.path.join(cwd,
                     str('camera-2_' + "{0:0=2d}".format(idx + 1) + '.jpg')))

# Removing some of the images where the corner was not detected
[os.remove(file) for file in glob.glob(os.path.join(cwd, '*06.jpg'))]
[os.remove(file) for file in glob.glob(os.path.join(cwd, '*01.jpg'))]

print("CALIBRATING THE CAMERAS")
deeplabcut.calibrate_cameras(path_config_file, calibrate=True)

print("CHECKING FOR UNDISTORTION")
deeplabcut.check_undistortion(path_config_file)

print("TRIANGULATING")
video_dir = os.path.join(basepath, folder)
deeplabcut.triangulate(path_config_file, video_dir)

print("CREATING LABELED VIDEO 3-D")
deeplabcut.create_labeled_video_3d(path_config_file, [video_dir],
                                   start=5,
                                   end=10)

#output_path = [os.path.join(basepath,folder)]
#deeplabcut.create_labeled_video_3d(path_config_file,output_path,start=5,end=10)

print("ALL DONE!!! - default cases are functional.")

print("Re-import DLC with env. variable set to test DLC light mode.")
os.environ['DLClight'] = 'True'
subprocess.call(['python3', "-c", "import deeplabcut"])
print("SUCCESS!!! - DLC light mode works too.")