Skip to content

Commit

Permalink
round fps to an integer as it sometimes leads to errors in VideoWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Dec 21, 2024
1 parent 8c33e4c commit 30b2022
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Pose2Sim/Utilities/Blazepose_runsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def blazepose_detec_func(**args):
# Run Blazepose
cap = cv2.VideoCapture(video_input)
W, H = cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
fps = round(cap.get(cv2.CAP_PROP_FPS))
count = 0
kpt_list = []
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5, model_complexity=model_complexity) as pose:
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def filter_all(config_dict):
cap.read()
if cap.read()[0] == False:
raise
frame_rate = int(cap.get(cv2.CAP_PROP_FPS))
frame_rate = round(cap.get(cv2.CAP_PROP_FPS))
except:
frame_rate = 60

Expand Down
4 changes: 2 additions & 2 deletions Pose2Sim/poseEstimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def process_video(video_path, pose_tracker, output_format, save_video, save_imag

if save_video: # Set up video writer
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for the output video
fps = cap.get(cv2.CAP_PROP_FPS) # Get the frame rate from the raw video
fps = round(cap.get(cv2.CAP_PROP_FPS)) # Get the frame rate from the raw video
W, H = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # Get the width and height from the raw video
out = cv2.VideoWriter(output_video_path, fourcc, fps, (W, H)) # Create the output video file

Expand Down Expand Up @@ -377,7 +377,7 @@ def rtm_estimator(config_dict):
cap = cv2.VideoCapture(video_files[0])
if not cap.isOpened():
raise FileNotFoundError(f'Error: Could not open {video_files[0]}. Check that the file exists.')
frame_rate = cap.get(cv2.CAP_PROP_FPS)
frame_rate = round(cap.get(cv2.CAP_PROP_FPS))
if frame_rate == 0:
frame_rate = 30
logging.warning(f'Error: Could not retrieve frame rate from {video_files[0]}. Defaulting to 30fps.')
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/synchronization.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def synchronize_cams_all(config_dict):
cap.read()
if cap.read()[0] == False:
raise
fps = int(cap.get(cv2.CAP_PROP_FPS))
fps = round(cap.get(cv2.CAP_PROP_FPS))
except:
fps = 60
lag_range = time_range_around_maxspeed*fps # frames
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def make_trc(config_dict, Q, keypoints_names, f_range, id_person=-1):
cap.read()
if cap.read()[0] == False:
raise
frame_rate = int(cap.get(cv2.CAP_PROP_FPS))
frame_rate = round(cap.get(cv2.CAP_PROP_FPS))
except:
frame_rate = 60

Expand Down

0 comments on commit 30b2022

Please sign in to comment.