Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import math
|
|
| 7 |
from tensorflow.keras.models import Model
|
| 8 |
from tensorflow.keras.layers import (LSTM, Dense, Dropout, Input, Flatten,
|
| 9 |
Bidirectional, Permute, multiply)
|
| 10 |
-
from moviepy.editor import VideoClip
|
| 11 |
|
| 12 |
# Load the pose estimation model from Mediapipe
|
| 13 |
mp_pose = mp.solutions.pose
|
|
@@ -70,7 +69,7 @@ class VideoProcessor:
|
|
| 70 |
temp_file.write(video_file.read())
|
| 71 |
# Now we can open the video file using cv2.VideoCapture()
|
| 72 |
cap = cv2.VideoCapture(filename)
|
| 73 |
-
|
| 74 |
while cap.isOpened():
|
| 75 |
ret, frame = cap.read()
|
| 76 |
if not ret:
|
|
@@ -78,11 +77,11 @@ class VideoProcessor:
|
|
| 78 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 79 |
results = self.pose.process(frame_rgb)
|
| 80 |
processed_frame = self.process_frame(frame, results)
|
| 81 |
-
|
| 82 |
cap.release()
|
| 83 |
# Remove the temporary file
|
| 84 |
os.remove(filename)
|
| 85 |
-
return
|
| 86 |
|
| 87 |
def process_frame(self, frame, results):
|
| 88 |
# Process the frame using the `process` function
|
|
@@ -265,14 +264,9 @@ def main():
|
|
| 265 |
video_file = st.file_uploader("Upload a video file", type=["mp4", "avi"])
|
| 266 |
if video_file is not None:
|
| 267 |
video_processor = VideoProcessor()
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
frame_index = int(t * 30) # Assuming 30 frames per second
|
| 272 |
-
return frames[frame_index]
|
| 273 |
-
|
| 274 |
-
video = VideoClip(make_frame, duration=len(frames) / 30)
|
| 275 |
-
st.video(video)
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
main()
|
|
|
|
| 7 |
from tensorflow.keras.models import Model
|
| 8 |
from tensorflow.keras.layers import (LSTM, Dense, Dropout, Input, Flatten,
|
| 9 |
Bidirectional, Permute, multiply)
|
|
|
|
| 10 |
|
| 11 |
# Load the pose estimation model from Mediapipe
|
| 12 |
mp_pose = mp.solutions.pose
|
|
|
|
| 69 |
temp_file.write(video_file.read())
|
| 70 |
# Now we can open the video file using cv2.VideoCapture()
|
| 71 |
cap = cv2.VideoCapture(filename)
|
| 72 |
+
output_frames = []
|
| 73 |
while cap.isOpened():
|
| 74 |
ret, frame = cap.read()
|
| 75 |
if not ret:
|
|
|
|
| 77 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 78 |
results = self.pose.process(frame_rgb)
|
| 79 |
processed_frame = self.process_frame(frame, results)
|
| 80 |
+
output_frames.append(processed_frame)
|
| 81 |
cap.release()
|
| 82 |
# Remove the temporary file
|
| 83 |
os.remove(filename)
|
| 84 |
+
return output_frames
|
| 85 |
|
| 86 |
def process_frame(self, frame, results):
|
| 87 |
# Process the frame using the `process` function
|
|
|
|
| 264 |
video_file = st.file_uploader("Upload a video file", type=["mp4", "avi"])
|
| 265 |
if video_file is not None:
|
| 266 |
video_processor = VideoProcessor()
|
| 267 |
+
output_frames = video_processor.process_video(video_file)
|
| 268 |
+
for frame in output_frames:
|
| 269 |
+
st.image(frame, channels="BGR")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
if __name__ == "__main__":
|
| 272 |
main()
|