TheKnight115 commited on
Commit
8be0123
·
verified ·
1 Parent(s): 9ec5726

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -27,6 +27,34 @@ def process_results(results, image):
27
 
28
  return image
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def main():
31
  st.title("Motorbike Violation Detection")
32
 
@@ -47,8 +75,8 @@ def main():
47
 
48
  elif uploaded_file.type == "video/mp4":
49
  # Process the video
50
- video_bytes = uploaded_file.read()
51
- st.video(video_bytes)
52
 
53
  if __name__ == "__main__":
54
  main()
 
27
 
28
  return image
29
 
30
+ def process_video(uploaded_file):
31
+ # Read the video file
32
+ video = cv2.VideoCapture(uploaded_file)
33
+ frames = []
34
+
35
+ while True:
36
+ ret, frame = video.read()
37
+ if not ret:
38
+ break # Break the loop if there are no frames left
39
+
40
+ # Run YOLO model on the current frame
41
+ results = run_yolo(frame)
42
+
43
+ # Process the results and draw boxes on the current frame
44
+ processed_frame = process_results(results, frame)
45
+ frames.append(processed_frame) # Save the processed frame
46
+
47
+ video.release()
48
+
49
+ # Create a video writer to save the processed frames
50
+ height, width, _ = frames[0].shape
51
+ out = cv2.VideoWriter('processed_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (width, height))
52
+
53
+ for frame in frames:
54
+ out.write(frame) # Write each processed frame to the video
55
+
56
+ out.release()
57
+
58
  def main():
59
  st.title("Motorbike Violation Detection")
60
 
 
75
 
76
  elif uploaded_file.type == "video/mp4":
77
  # Process the video
78
+ process_video(uploaded_file) # Process the video and save the output
79
+ st.video('processed_video.mp4') # Display the processed video
80
 
81
  if __name__ == "__main__":
82
  main()