Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
import cv2
|
4 |
import mediapipe as mp
|
@@ -46,27 +45,27 @@ class VideoProcessor:
|
|
46 |
self.model = build_model()
|
47 |
|
48 |
def process_video(self, video_file):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
def draw_landmarks(self, image, results):
|
72 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import cv2
|
3 |
import mediapipe as mp
|
|
|
45 |
self.model = build_model()
|
46 |
|
47 |
def process_video(self, video_file):
|
48 |
+
# Get the filename from the file object
|
49 |
+
filename = video_file.name
|
50 |
+
# Create a temporary file to write the contents of the uploaded video file
|
51 |
+
temp_file = open(filename, 'wb')
|
52 |
+
temp_file.write(video_file.read())
|
53 |
+
temp_file.close()
|
54 |
+
# Now we can open the video file using cv2.VideoCapture()
|
55 |
+
cap = cv2.VideoCapture(filename)
|
56 |
+
out_frames = []
|
57 |
+
while cap.isOpened():
|
58 |
+
ret, frame = cap.read()
|
59 |
+
if not ret:
|
60 |
+
break
|
61 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
62 |
+
results = self.pose.process(frame_rgb)
|
63 |
+
frame = self.draw_landmarks(frame, results)
|
64 |
+
out_frames.append(frame)
|
65 |
+
cap.release()
|
66 |
+
# Remove the temporary file
|
67 |
+
os.remove(filename)
|
68 |
+
return out_frames
|
69 |
|
70 |
def draw_landmarks(self, image, results):
|
71 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
|