Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Mar 24, 2024
1 parent d703933 commit 0008c7e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
12 changes: 10 additions & 2 deletions Sports2D/Utilities/skeletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,17 @@
]),
]),
]),
Node("Nose", id=0, children=[
Node("REye", id=5),
Node("Nose", id=0, children=[
Node("LEyeInner", id=1),
Node("LEye", id=2),
Node("LEyeOuter", id=3),
Node("REyeInner", id=4),
Node("REye", id=5),
Node("REyeOuter", id=6),
Node("LEar", id=7),
Node("REar", id=8),
Node("LMouth", id=9),
Node("RMouth", id=10),
]),
Node("RShoulder", id=12, children=[
Node("RElbow", id=14, children=[
Expand Down
7 changes: 5 additions & 2 deletions Sports2D/compute_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def segment_angles_series_from_points(df_points, angle_params, segment):
ang_series = points2D_to_angles(points_list)
ang_series += angle_params[2]
ang_series *= angle_params[3]
ang_series = np.where(ang_series>180,ang_series-360,ang_series)
# ang_series = np.where(ang_series>180,ang_series-360,ang_series)

# For trunk: mean between angles RHip-RShoulder and LHip-LShoulder
if segment == 'Trunk':
Expand All @@ -264,7 +264,10 @@ def segment_angles_series_from_points(df_points, angle_params, segment):
ang_series += angle_params[2]
ang_series *= angle_params[3]
ang_series = np.mean((ang_seriesR, ang_series), axis=0)
ang_series = np.where(ang_series>180,ang_series-360,ang_series)
# ang_series = np.where(ang_series>180,ang_series-360,ang_series)

if ang_series.mean() > 180: ang_series -= 360
if ang_series.mean() < -180: ang_series += 360

return ang_series

Expand Down
52 changes: 34 additions & 18 deletions Sports2D/detect_pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ def min_with_single_indices(L, T):
- T_minL: list of tuples associated with smallest values of L
'''

minL = [np.min(L)]
try:
minL = [np.min(L)]
except:
return [], [], []
argminL = [np.argmin(L)]
T_minL = [T[argminL[0]]]

Expand Down Expand Up @@ -492,9 +495,13 @@ def save_imgvid_reID(video_path, video_result_path, save_vid=1, save_img=1, *pos

# Open csv files
coords = []
for c in csv_paths:
with open(c) as c_f:
coords += [pd.read_csv(c_f, header=[0,1,2,3])]
try:
for c in csv_paths:
with open(c) as c_f:
coords += [pd.read_csv(c_f, header=[0,1,2,3])]
except:
logging.warning('No csv files found.')
return

# Open video frame by frame
cap = cv2.VideoCapture(str(video_path))
Expand Down Expand Up @@ -535,7 +542,8 @@ def save_imgvid_reID(video_path, video_result_path, save_vid=1, save_img=1, *pos
break
f += 1
cap.release()
writer.release()
if save_vid:
writer.release()


def detect_pose_fun(config_dict, video_file):
Expand Down Expand Up @@ -625,21 +633,29 @@ def detect_pose_fun(config_dict, video_file):
elif platform == "linux" or platform=="linux2":
run_openpose_linux(video_path, json_path, pose_model)
os.chdir(root_dir)



elif pose_algo == 'BLAZEPOSE':
pose_model = pose_algo
json_path = result_dir / '_'.join((video_file_stem,pose_algo,'json'))
model_complexity = config_dict.get('pose').get('BLAZEPOSE').get('model_complexity')
Blazepose_runsave.blazepose_detec_func(input_file=video_path, save_images=False, to_json=True, save_video=False, to_csv=False, output_folder=result_dir, model_complexity=model_complexity)

# Sort people and save to csv, optionally display plot
try:
json_to_csv(json_path, frame_rate, pose_model, interp_gap_smaller_than, filter_options, show_plots)
except:
logging.warning('No person detected or persons could not be associated across frames.')
return

# Save images and files after reindentification
if save_img and save_vid:
logging.info(f'Saving images and video in {result_dir}.')
if save_img and not save_vid:
logging.info(f'Saving images in {result_dir}.')
if not save_img and save_vid:
logging.info(f'Saving video in {result_dir}.')
if save_vid or save_img:
save_imgvid_reID(video_path, video_result_path, save_vid, save_img, pose_model)
if save_img and save_vid:
logging.info(f'Saving images and video in {result_dir}.')
if save_img and not save_vid:
logging.info(f'Saving images in {result_dir}.')
if not save_img and save_vid:
logging.info(f'Saving video in {result_dir}.')
if save_vid or save_img:
save_imgvid_reID(video_path, video_result_path, save_vid, save_img, pose_model)


elif pose_algo == 'BLAZEPOSE':
model_complexity = config_dict.get('pose').get('BLAZEPOSE').get('model_complexity')
Blazepose_runsave.blazepose_detec_func(input_file=video_path, save_images=save_img, to_json=True, save_video=save_vid, to_csv=True, output_folder=result_dir, model_complexity=model_complexity)

4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = sports2d
version = 0.3.3
version = 0.3.4
author = David Pagnon
author_email = contact@david-pagnon.com
description = Detect pose and compute 2D joint angles from a video.
Expand Down Expand Up @@ -38,7 +38,7 @@ install_requires =
scipy
anytree
opencv-python
mediapipe==0.10.0
mediapipe
matplotlib
PyQt5
statsmodels
Expand Down

0 comments on commit 0008c7e

Please sign in to comment.