@@ -24,7 +24,7 @@ def compute_center_velocity(pose_start, pose_end, fps, window_size):
2424 com_end = compute_center_of_mass (pose_end )
2525 dx = com_end [0 ] - com_start [0 ]
2626 dy = com_end [1 ] - com_start [1 ]
27- distance = math .sqrt (dx ** 2 + dy ** 2 )
27+ distance = math .sqrt (dx ** 2 + dy ** 2 )
2828 time_elapsed = (window_size - 1 ) / fps
2929 velocity = distance / time_elapsed
3030 return min (velocity , 300.0 ), dy
@@ -50,7 +50,7 @@ def find_most_similar_pose(reference_pose, candidate_poses):
5050 best_pose = None
5151 for pose in candidate_poses :
5252 cx , cy = compute_center_of_mass (pose )
53- dist = (ref_cx - cx )** 2 + (ref_cy - cy )** 2
53+ dist = (ref_cx - cx ) ** 2 + (ref_cy - cy ) ** 2
5454 if dist < min_dist :
5555 min_dist = dist
5656 best_pose = pose
@@ -101,7 +101,7 @@ def prepare_vid_out(video_path, vid_cap, output_dir):
101101
102102 vid_write_image = letterbox (first_frame , 960 , stride = 64 , auto = True )[0 ]
103103 resize_height , resize_width = vid_write_image .shape [:2 ]
104- video_name = os .path .basename (video_path ).split ('.' )[0 ] + "_output.mp4"
104+ video_name = os .path .basename (video_path ).split ("." )[0 ] + "_output.mp4"
105105 out_video_name = os .path .join (output_dir , video_name )
106106 print (f"[INFO] Writing output to: { out_video_name } " )
107107
@@ -114,7 +114,9 @@ def prepare_vid_out(video_path, vid_cap, output_dir):
114114 return out
115115
116116
117- def fall_detection (pose_window , window_size , fps , v_thresh , aspect_ratio_thresh , dy_thresh ):
117+ def fall_detection (
118+ pose_window , window_size , fps , v_thresh , aspect_ratio_thresh , dy_thresh
119+ ):
118120 if len (pose_window ) < window_size :
119121 return False , None , None , None
120122
@@ -131,14 +133,14 @@ def fall_detection(pose_window, window_size, fps, v_thresh, aspect_ratio_thresh,
131133 f"ar={ ar_delta :.2f} /{ aspect_ratio_thresh :.2f} "
132134 )
133135 print (f"[TRACE] { debug_text } " )
134-
136+
135137 cond_speed_drop = v > v_thresh and dy > dy_thresh
136138 cond_down_flat = dy > dy_thresh and ar_delta > aspect_ratio_thresh
137139
138140 if cond_speed_drop or cond_down_flat :
139141 tag = (
140- ("SpeedDrop " if cond_speed_drop else "" ) +
141- ("DownFlat " if cond_down_flat else "" )
142+ ("SpeedDrop " if cond_speed_drop else "" )
143+ + ("DownFlat " if cond_down_flat else "" )
142144 ).strip ()
143145
144146 xmin = pose_end [2 ] - pose_end [4 ] / 2
@@ -171,8 +173,10 @@ def falling_alarm(image, bbox):
171173 lineType = cv2 .LINE_AA ,
172174 )
173175
176+
174177def draw_fps (frame , prev_time ):
175178 import time
179+
176180 curr_time = time .time ()
177181 fps = 1 / (curr_time - prev_time )
178182 cv2 .putText (
@@ -186,4 +190,3 @@ def draw_fps(frame, prev_time):
186190 cv2 .LINE_AA ,
187191 )
188192 return frame , curr_time
189-
0 commit comments