adewopova commited on
Commit
640dd38
·
unverified ·
1 Parent(s): 8240226
Files changed (1) hide show
  1. accident_app.py +1 -38
accident_app.py CHANGED
@@ -27,9 +27,7 @@ def load_and_preprocess_video(video_path):
27
  frame = frame[:, :, [2, 1, 0]]
28
  frames.append(frame)
29
  cap.release()
30
- # print("Total Frames:", total_frames)
31
- # print("Frames per Second:", fps)
32
- # print("frame processed:",len(frames))
33
  return np.array(frames)
34
 
35
 
@@ -88,41 +86,6 @@ def create_chunks_from_frames(frames, window_size=30):
88
  return chunks
89
 
90
 
91
- # def overlay_predictions_to_video(frames, predictions):
92
- # temp_dir = 'temp_frames'
93
-
94
- # # Clear existing frames and video if they exist
95
- # if os.path.exists(temp_dir):
96
- # shutil.rmtree(temp_dir)
97
- # os.makedirs(temp_dir)
98
-
99
- # video_output_path = 'p_user_upload.mp4'
100
- # if os.path.exists(video_output_path):
101
- # os.remove(video_output_path)
102
-
103
- # frame_idx = 0
104
-
105
- # for prediction in predictions:
106
- # # Overlay the prediction for WINDOW_SIZE frames
107
- # if frame_idx >= len(frames): # Make sure not to exceed total frames
108
- # break
109
- # frame = frames[frame_idx]
110
-
111
- # frame_idx += 1
112
- # color = (0, 255, 0) if prediction[1] > prediction[0] else (255, 0, 0)
113
- # frame = cv2.putText(frame, f"Accident: {prediction[0]:.2f}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2, cv2.LINE_AA)
114
- # frame = cv2.putText(frame, f"No Accident: {prediction[1]:.2f}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2, cv2.LINE_AA)
115
- # frame = frame[:, :, [2, 1, 0]]
116
-
117
- # # Save frame to disk
118
- # cv2.imwrite(os.path.join(temp_dir, f'frame_{frame_idx:04d}.png'), frame)
119
-
120
- # # Use ffmpeg to stitch frames into video
121
- # cmd = f"ffmpeg -framerate 20 -i {temp_dir}/frame_%04d.png -c:v libx264 -pix_fmt yuv420p {video_output_path}"
122
- # subprocess.call(cmd, shell=True)
123
-
124
- # # Remove the temporary frames directory
125
- # shutil.rmtree(temp_dir)
126
  def overlay_predictions_to_video(frames, predictions):
127
  temp_dir = 'temp_frames'
128
 
 
27
  frame = frame[:, :, [2, 1, 0]]
28
  frames.append(frame)
29
  cap.release()
30
+
 
 
31
  return np.array(frames)
32
 
33
 
 
86
  return chunks
87
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  def overlay_predictions_to_video(frames, predictions):
90
  temp_dir = 'temp_frames'
91