Spaces:
Running
Running
add
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import mediapipe as mp
|
5 |
+
|
6 |
+
def convert_and_process(uploaded_file):
|
7 |
+
with open("temp.mp4", "wb") as f:
|
8 |
+
f.write(uploaded_file.getbuffer())
|
9 |
+
|
10 |
+
# Convert to desired format (replace with your preferred format)
|
11 |
+
cap = cv2.VideoCapture("temp.mp4")
|
12 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
13 |
+
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (int(cap.get(3)), int(cap.get(4))))
|
14 |
+
|
15 |
+
# Initialize Mediapipe Pose
|
16 |
+
mp_pose = mp.solutions.pose
|
17 |
+
with mp_pose.Pose() as pose:
|
18 |
+
while True:
|
19 |
+
ret, frame = cap.read()
|
20 |
+
if not ret:
|
21 |
+
break
|
22 |
+
|
23 |
+
# Convert to RGB for Mediapipe
|
24 |
+
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
25 |
+
results = pose.process(image)
|
26 |
+
|
27 |
+
# Draw skeleton stickfigure (basic implementation)
|
28 |
+
if results.pose_landmarks:
|
29 |
+
for id, lm in enumerate(results.pose_landmarks.landmark):
|
30 |
+
h, w, c = image.shape
|
31 |
+
cx, cy = int(lm.x * w), int(lm.y
|
32 |
+
* h)
|
33 |
+
cv2.circle(image, (cx, cy), 5, (255, 0, 0), cv2.FILLED)
|
34 |
+
|
35 |
+
|
36 |
+
# Write the frame with stickfigures to the output video
|
37 |
+
out.write(image)
|
38 |
+
|
39 |
+
cap.release()
|
40 |
+
out.release()
|
41 |
+
|
42 |
+
def main():
|
43 |
+
st.title("Video Upload and Processing")
|
44 |
+
uploaded_file = st.file_uploader("Upload a video")
|
45 |
+
if uploaded_file is not None:
|
46 |
+
convert_and_process(uploaded_file)
|
47 |
+
st.video('output.mp4')
|
48 |
+
|
49 |
+
if __name__ == '__main__':
|
50 |
+
main()
|