Skip to content

Commit

Permalink
solve sorting issue on linux and colab
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed May 8, 2023
1 parent 724fed9 commit c0224f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
30 changes: 25 additions & 5 deletions Sports2D/Sports2D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "dc0h3Mq8RcvS"
},
"source": [
"Batch run all uploaded videos with Sports2D"
"Batch run all uploaded videos with Sports2D.\\\n",
"If you want to work with BlazePose, comment the last two lines of the following cell."
]
},
{
Expand Down Expand Up @@ -251,14 +253,21 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Retrieve results"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "0avZJwEfStiT"
},
"source": [
"## Show results\n",
"\n",
"Show video"
"## Show video"
]
},
{
Expand All @@ -279,6 +288,14 @@
" </video>'''.format(width, height, video_encoded.decode('ascii')))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Edit the path below with the name of your output video"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -293,12 +310,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "vJijh-gK3Wvg"
},
"source": [
"Plot angles"
"## Plot angles\n",
"\n",
"Edit the path below with the name of your output csv file"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions Sports2D/compute_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def compute_angles_fun(config_dict):

# Find csv position files in video_dir, search pose_model and video_file.stem
logging.info(f'Retrieving csv position files in {video_dir}...')
csv_paths = list(video_dir.glob(f'*{video_file.stem}_{pose_model}_*points*.csv'))
csv_paths = sorted(video_dir.glob(f'*{video_file.stem}_{pose_model}_*points*.csv'))
logging.info(f'{len(csv_paths)} persons found.')

# Compute angles
Expand Down Expand Up @@ -464,7 +464,7 @@ def compute_angles_fun(config_dict):
writer = cv2.VideoWriter(str(video_pose2), fourcc, fps, (int(W), int(H)))

# Preferentially from pose image files
frames_img = list(img_pose.glob('*'))
frames_img = sorted(img_pose.glob('*'))
if len(frames_img)>0:
for frame_nb in range(df_angles_list[0].shape[0]):
df_angles_list_frame = [df_angles_list[n].iloc[frame_nb,:] for n in range(len(df_angles_list))]
Expand Down
8 changes: 4 additions & 4 deletions Sports2D/detect_pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def json_to_csv(json_path, pose_model, interp_gap_smaller_than, filter_options,

# Retrieve coordinates
logging.info('Sorting people across frames.')
json_fnames = list(json_path.glob('*.json'))
json_fnames = sorted(json_path.glob('*.json'))
nb_persons_to_detect = max([len(json.load(open(json_fname))['people']) for json_fname in json_fnames])
Coords = [np.array([]).reshape(0,keypoints_nb*3)] * nb_persons_to_detect
for json_fname in json_fnames: # for each frame
Expand Down Expand Up @@ -455,9 +455,9 @@ def save_imgvid_reID(video_path, save_vid=1, save_img=1, *pose_model):

# Find csv position files, prepare video and image saving paths
pose_model = pose_model[0]
csv_paths = list(video_path.parent.glob(f'*{video_path.stem}*{pose_model}*points*refined*.csv'))
csv_paths = sorted(video_path.parent.glob(f'*{video_path.stem}*{pose_model}*points*refined*.csv'))
if csv_paths == []:
csv_paths = list(video_path.parent.glob(f'*{video_path.stem}*{pose_model}*points*.csv'))
csv_paths = sorted(video_path.parent.glob(f'*{video_path.stem}*{pose_model}*points*.csv'))

# Open csv files
coords = []
Expand All @@ -480,7 +480,7 @@ def save_imgvid_reID(video_path, save_vid=1, save_img=1, *pose_model):
img_pose_path.mkdir(parents=True, exist_ok=True)

f = 0
while(cap.isOpened()):
while(cap.isOpened() and f < len(coords[0])):
ret, frame = cap.read()
if ret == True:
X = [np.array(coord.iloc[f,1::3]) for coord in coords]
Expand Down

0 comments on commit c0224f0

Please sign in to comment.