Skip to content

Commit

Permalink
Synchronize multi cams based on keypoints speed. (#76) @rlagnsals
Browse files Browse the repository at this point in the history
@rlagnsals 

* synchronization

* Auto Synchronization

* Auto Synchronization

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Auto Synchronization

* Update synchronize_cams.py

* Auto Synchronization

* Delete Pose2Sim/S00_Demo_Session/Config.toml

* Add files via upload

* Update Config.toml
  • Loading branch information
hunminkim98 authored Mar 15, 2024
1 parent ce0abe1 commit 5ddef52
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 41 deletions.
60 changes: 30 additions & 30 deletions Pose2Sim/Pose2Sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,43 +265,43 @@ def synchronization(config=None):
or a the directory path of a trial, participant, or session,
or the function can be called without an argument, in which case it the config directory is the current one.
'''

raise NotImplementedError('This has not been integrated yet. \nPlease read README.md for further explanation')

# #TODO
# # Determine the level at which the function is called (session:3, participant:2, trial:1)
# level, config_dicts = read_config_files(config)
# Import the function
from Pose2Sim.synchronize_cams import synchronize_cams_all

# if type(config)==dict:
# config_dict = config_dicts[0]
# if config_dict.get('project').get('project_dir') == None:
# raise ValueError('Please specify the project directory in config_dict:\n \
# config_dict.get("project").update({"project_dir":"<YOUR_TRIAL_DIRECTORY>"})')
# Determine the level at which the function is called (session:3, participant:2, trial:1)
level, config_dicts = read_config_files(config)

# # Set up logging
# session_dir = os.path.realpath(os.path.join(config_dicts[0].get('project').get('project_dir'), '..', '..'))
# setup_logging(session_dir)
if type(config)==dict:
config_dict = config_dicts[0]
if config_dict.get('project').get('project_dir') == None:
raise ValueError('Please specify the project directory in config_dict:\n \
config_dict.get("project").update({"project_dir":"<YOUR_TRIAL_DIRECTORY>"})')

# # Batch process all trials
# for config_dict in config_dicts:
# start = time.time()
# currentDateAndTime = datetime.now()
# project_dir = os.path.realpath(config_dict.get('project').get('project_dir'))
# seq_name = os.path.basename(project_dir)
# frame_range = config_dict.get('project').get('frame_range')
# frames = ["all frames" if frame_range == [] else f"frames {frame_range[0]} to {frame_range[1]}"][0]
# Set up logging
session_dir = os.path.realpath(os.path.join(config_dicts[0].get('project').get('project_dir'), '..', '..'))
setup_logging(session_dir)

# logging.info("\n\n---------------------------------------------------------------------")
# logging.info("Camera synchronization")
# logging.info(f"On {currentDateAndTime.strftime('%A %d. %B %Y, %H:%M:%S')}")
# logging.info("---------------------------------------------------------------------")
# logging.info(f"\nProject directory: {project_dir}")
# Batch process all trials
for config_dict in config_dicts:
start = time.time()
currentDateAndTime = datetime.now()
project_dir = os.path.realpath(config_dict.get('project').get('project_dir'))
seq_name = os.path.basename(project_dir)
frame_range = config_dict.get('project').get('frame_range')
frames = ["all frames" if frame_range == [] else f"frames {frame_range[0]} to {frame_range[1]}"][0]

logging.info("\n\n---------------------------------------------------------------------")
logging.info("Camera synchronization")
logging.info(f"On {currentDateAndTime.strftime('%A %d. %B %Y, %H:%M:%S')}")
logging.info("---------------------------------------------------------------------")
logging.info(f"\nProject directory: {project_dir}")

# synchronize_cams_all(config_dict)
synchronize_cams_all(config_dict)

# end = time.time()
# elapsed = end-start
# logging.info(f'Synchronization took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.')
end = time.time()
elapsed = end-start
logging.info(f'Synchronization took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.')


def personAssociation(config=None):
Expand Down
14 changes: 4 additions & 10 deletions Pose2Sim/S00_Demo_Session/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[project]
# multi_person = false # true for trials with multiple participants. If false, only the main person in scene is analyzed (and it run much faster).
nb_persons_to_detect = 2 # checked only if multi_person is selected
frame_rate = 60 # fps
frame_rate = 120 # fps
frame_range = [] # For example [10,300], or [] for all frames
## N.B.: If you want a time range instead, use frame_range = time_range * frame_rate
## For example if you want to analyze from 0.1 to 2 seconds with a 60 fps frame rate,
Expand Down Expand Up @@ -104,15 +104,9 @@ openpose_path = '' # only checked if OpenPose is used
[synchronization]
# COMING SOON!
reset_sync = true # Recalculate synchronization even if already done
frames = [2850,3490] # Frames to use for synchronization, should point to a moment with fast motion.
cut_off_frequency = 10 # cut-off frequency for a 4th order low-pass Butterworth filter
# Vertical speeds (on X, Y, or Z axis, or 2D speeds)
speed_kind = 'y' # 'x', 'y', 'z', or '2D'
vmax = 20 # px/s
cam1_nb = 4
cam2_nb = 3
id_kpt = [9,10] # Pour plus tard aller chercher numéro depuis keypoint name dans skeleton.py. 'RWrist' BLAZEPOSE 16, BODY_25B 10, BODY_25 4 ; 'LWrist' BLAZEPOSE 15, BODY_25B 9, BODY_25 7
weights_kpt = [1,1] # Pris en compte uniquement si on a plusieurs keypoints
speed_kind = 'y' # 'y' showed best performance.
id_kpt = [10] # number from keypoint name in skeleton.py. RWrist' BLAZEPOSE 16, BODY_25B 10, BODY_25 4 ; 'LWrist' BLAZEPOSE 15, BODY_25B 9, BODY_25 7
weights_kpt = [1] # Only taken into account if you have several keypoints (Currently only one keypoint is supported).


[personAssociation]
Expand Down
Loading

0 comments on commit 5ddef52

Please sign in to comment.