Newer
Older
Cribellier, Antoine
committed
from process.batch_processing import BatchProcessing
Cribellier, Antoine
committed
# TODO Update from examples in test_process_batch
Cribellier, Antoine
committed
xyz_path = os.path.join(os.getcwd(), 'data/calib/examples/mosquito_escapes/to_delete/xyz_calibration_device_small.csv')
#xy_path = os.path.join(os.getcwd(), 'data/calib/20200615_xypts-rot.csv')
Cribellier, Antoine
committed
xy_path = os.path.join(os.getcwd(), 'data/calib/examples/mosquito_escapes/to_delete/20200615_xypts.csv')
dlt_path = os.path.join(os.getcwd(), 'data/calib/examples/mosquito_escapes/to_delete/20200615_DLTcoefs-py.csv')
dlc_cfg_path = '/home/user/Desktop/Antoine/_DLC/config.yaml'
img_size = (896, 896)
# Generate dlt coefficients
#gen_dlt(3, img_size, xyz_path, xy_path, dlt_path)
Cribellier, Antoine
committed
img_process = BatchProcessing()
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
img_process.cam_paths = {1: '/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics',
2: '/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics',
3: '/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics'}
img_process.cam_save_paths = {1: '/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics/_Process',
2: '/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics/_Process',
3: '/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics/_Process'}
img_process.update_leading_zero = False
img_process.init_paths_names()
img_process.max_diff_date_s = 90
img_process.show_plot = False
# # Fill dict with name of recordings to process
# # > either all recordings from a given date
# date_to_process = '20200303'
# rec_names_to_process = {}
# for camn in range(1, img_process.nb_cam + 1):
# rec_names_to_process[camn] = [s for s in img_process.all_folders_rec_cam[camn] if date_to_process in s]
# > all recordings
rec_names_to_process = {}
for camn in range(1, img_process.nb_cam + 1):
rec_names_to_process[camn] = img_process.all_folders_rec_cam[camn]
# # Keep only rec_names that haven't been processed yet
# non_processed_rec_names = {1: [], 2: [], 3: []}
# for camn in range(1, img_process.nb_cam + 1):
# for i, rec_name in enumerate(rec_names_to_process[camn]):
# if not os.path.exists(os.path.join(img_process.cam_save_paths[camn], '_Avi', rec_name)):
# non_processed_rec_names[camn].append(rec_names_to_process[camn][i])
#
# rec_names_to_process = non_processed_rec_names
# -----------------------------------------------------------------------------------------------------------------------
# Will prepare recordings to be used by Deeplabcut
# > do everything automatically use 'multi_processes'
# Do cropping, rotating, stitching, etc at once and save as .avi (save much time and space)
Cribellier, Antoine
committed
img_process._do_batch('multi_processes', rec_names_to_process=rec_names_to_process, yaml_path='processes.yaml', delete_previous=True)
Cribellier, Antoine
committed
# Convert images to 8 bits and reduce frame_rate (save in cam_save_paths/_Sample)
Cribellier, Antoine
committed
# img_process.do_batch('sample', rec_names_to_process=rec_names_to_process, step_frame=50, delete_previous=True)
#
# # Do 2d tracking (blob detection) on images in cam_save_paths/_Sample
Cribellier, Antoine
committed
# img_process.do_batch('track2d', rec_names_to_process=rec_names_to_process, from_fn_name='sample')
Cribellier, Antoine
committed
# img_process.do_batch('recon3d', rec_names_to_process=rec_names_to_process, from_fn_name='sample', dlt_path=dlt_path)
#
# # Crop all frames and save in cam_save_paths/_Cropped
Cribellier, Antoine
committed
# img_process.do_batch('crop', rec_names_to_process=rec_names_to_process, from_fn_name='sample', height_crop=200, width_crop=200, delete_previous=True)
#
# # Rotate view 2 (to always have piston coming from right side)
Cribellier, Antoine
committed
# img_process.do_batch('rotate', rec_names_to_process=rec_names_to_process, from_fn_name='crop', camn_to_process=[2], degrees=270)
#
# # Stitch all views together and save in cam_save_paths/_Stitched
Cribellier, Antoine
committed
# img_process.do_batch('stitch', rec_names_to_process=rec_names_to_process, from_fn_name='crop', delete_previous=True)
# -----------------------------------------------------------------------------------------------------------------------
# Run Deeplabcut analysis + Fit 3D skeleton to 2D coordinate from Deeplabcut
dlc_cfg_path = '/home/user/Desktop/Antoine/_maDLC/config.yaml'
shuffle = 31
iteration = 70000
model_name = 'DLC_resnet50_MatingKinematicsshuffle{0}_{1}'.format(shuffle, iteration)
res_method = '3d' # '2d', '3d' or '2d_geo'
opt_method = 'leastsq' # 'powell' or 'leastsq' or 'least_squares'
body_param_names = ['yaw_a', 'pitch_a', 'roll_a', 'x_com', 'y_com', 'z_com']
wing_param_names = ['stroke_a', 'deviation_a', 'rotation_a']
# # Track features using DeepLabCut
Cribellier, Antoine
committed
# img_process.do_batch('analyse_dlc', rec_names_to_process=rec_names_to_process, from_fn_name='save_avi', cfg_path=dlc_cfg_path,
Cribellier, Antoine
committed
# shuffle=shuffle, trainingset_index=0, batch_size=5, save_avi=False, model_name=model_name, delete_previous=True)
# # Load (+ filtering and unscrambling) 2d coords from DLC + Reverse processes (unstitch, rotate back, uncrop) + Reconstruct 3d coord
Cribellier, Antoine
committed
# img_process.do_batch('load_dlc', rec_names_to_process=rec_names_to_process, from_fn_name='analyse_dlc', model_name=model_name,
Cribellier, Antoine
committed
# tracker_method='skeleton', dlt_path=dlt_path)
# # Optimize fit of skeleton to find body and wings angles
# img_process.multiprocessing = True
# img_process.threshold_likelihood = 0.85
Cribellier, Antoine
committed
# img_process.do_batch('fit_skeleton', rec_names_to_process=rec_names_to_process, from_fn_name='load_dlc', model_name=model_name,
# csv_path=csv_wings_geo_path, body_param_names=body_param_names, wing_param_names=wing_param_names,
Cribellier, Antoine
committed
# animal_name="fly", res_method=res_method, opt_method=opt_method, dlt_path=dlt_path)
print('> All processes as been processed (total time elapsed: {0:.4f} s)'.format(time.time() - start))