Medvira commited on
Commit
77123ea
·
verified ·
1 Parent(s): d30ec5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -23,6 +23,7 @@ if uploaded_file is not None:
23
  cap = cv2.VideoCapture(tfile.name)
24
  assert cap.isOpened(), "Error reading video file"
25
  w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
 
26
 
27
  # Initialize AIGym object
28
  gym_object = solutions.AIGym(
@@ -35,6 +36,10 @@ if uploaded_file is not None:
35
  # List to store processed frames
36
  processed_frames = []
37
 
 
 
 
 
38
  # Process the video frame by frame
39
  st.write("Analyzing video... Please wait.")
40
  while cap.isOpened():
@@ -45,18 +50,25 @@ if uploaded_file is not None:
45
  results = model.track(im0, verbose=False) # Tracking recommended
46
  im0 = gym_object.start_counting(im0, results)
47
 
 
 
 
48
  # Append the processed frame to the list
49
- processed_frames.append(im0)
 
 
 
 
50
 
51
  cap.release()
52
  cv2.destroyAllWindows()
53
 
54
  # Create a temporary file to save the processed video
55
- output_video_file = tempfile.NamedTemporaryFile(delete=False, suffix='.avi')
56
  output_video_path = output_video_file.name
57
 
58
  # Write the processed frames to a video file
59
- video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
60
  for frame in processed_frames:
61
  video_writer.write(frame)
62
  video_writer.release()
@@ -68,4 +80,4 @@ if uploaded_file is not None:
68
  # Provide a download link for the processed video
69
  st.write("Download the processed video:")
70
  with open(output_video_path, "rb") as video_file:
71
- st.download_button("Download", video_file, "workouts.avi")
 
23
  cap = cv2.VideoCapture(tfile.name)
24
  assert cap.isOpened(), "Error reading video file"
25
  w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
26
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
27
 
28
  # Initialize AIGym object
29
  gym_object = solutions.AIGym(
 
36
  # List to store processed frames
37
  processed_frames = []
38
 
39
+ # Streamlit progress bar
40
+ progress_bar = st.progress(0)
41
+ frame_count = 0
42
+
43
  # Process the video frame by frame
44
  st.write("Analyzing video... Please wait.")
45
  while cap.isOpened():
 
50
  results = model.track(im0, verbose=False) # Tracking recommended
51
  im0 = gym_object.start_counting(im0, results)
52
 
53
+ # Resize the frame to 320x320
54
+ im0_resized = cv2.resize(im0, (320, 320))
55
+
56
  # Append the processed frame to the list
57
+ processed_frames.append(im0_resized)
58
+
59
+ # Update progress bar
60
+ frame_count += 1
61
+ progress_bar.progress(frame_count / total_frames)
62
 
63
  cap.release()
64
  cv2.destroyAllWindows()
65
 
66
  # Create a temporary file to save the processed video
67
+ output_video_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4')
68
  output_video_path = output_video_file.name
69
 
70
  # Write the processed frames to a video file
71
+ video_writer = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (320, 320))
72
  for frame in processed_frames:
73
  video_writer.write(frame)
74
  video_writer.release()
 
80
  # Provide a download link for the processed video
81
  st.write("Download the processed video:")
82
  with open(output_video_path, "rb") as video_file:
83
+ st.download_button("Download", video_file, "workouts.mp4")