Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import cv2
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import numpy as np
|
| 4 |
import mediapipe as mp
|
|
@@ -46,7 +47,7 @@ def draw_landmarks(img, landmarks):
|
|
| 46 |
height, width, _ = img.shape
|
| 47 |
for lm in landmarks.landmark:
|
| 48 |
cx, cy = int(lm.x * width), int(lm.y * height)
|
| 49 |
-
cv2.circle(img, (cx, cy),
|
| 50 |
|
| 51 |
for connection in POSE_CONNECTIONS:
|
| 52 |
start_idx, end_idx = connection
|
|
@@ -57,7 +58,7 @@ def draw_landmarks(img, landmarks):
|
|
| 57 |
start_coordinates = (int(start_point.x * width), int(start_point.y * height))
|
| 58 |
end_coordinates = (int(end_point.x * width), int(end_point.y * height))
|
| 59 |
|
| 60 |
-
cv2.line(img, start_coordinates, end_coordinates, (0, 255, 0),
|
| 61 |
|
| 62 |
return img
|
| 63 |
|
|
@@ -136,6 +137,8 @@ def main():
|
|
| 136 |
|
| 137 |
operation_type = st.radio("Choose operation type", ("Input", "Demo"))
|
| 138 |
|
|
|
|
|
|
|
| 139 |
if operation_type == "Input":
|
| 140 |
input_type = st.radio("Choose input type", ("Image", "Video"))
|
| 141 |
|
|
@@ -152,8 +155,6 @@ def main():
|
|
| 152 |
|
| 153 |
draw_box = st.checkbox("Draw bounding box", value=False)
|
| 154 |
|
| 155 |
-
pose = mp_pose.Pose()
|
| 156 |
-
|
| 157 |
if uploaded_file is not None:
|
| 158 |
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 159 |
temp_file.write(uploaded_file.read())
|
|
@@ -171,6 +172,7 @@ def main():
|
|
| 171 |
frame = process_frame(frame, pose, draw_box)
|
| 172 |
|
| 173 |
st_frame.image(frame, channels='BGR', use_column_width=True)
|
|
|
|
| 174 |
st.empty()
|
| 175 |
|
| 176 |
st.text("Completed")
|
|
@@ -186,23 +188,13 @@ def main():
|
|
| 186 |
st.empty()
|
| 187 |
st.markdown("<p class='intro'>Demo video will be shown below:</p>", unsafe_allow_html=True)
|
| 188 |
|
| 189 |
-
|
| 190 |
-
cam = cv2.VideoCapture(demo_video_path)
|
| 191 |
-
st_frame = st.empty()
|
| 192 |
-
pose = mp_pose.Pose()
|
| 193 |
-
|
| 194 |
-
while cam.isOpened():
|
| 195 |
-
success, frame = cam.read()
|
| 196 |
-
if not success:
|
| 197 |
-
break
|
| 198 |
-
|
| 199 |
-
frame = process_frame(frame, pose, draw_box=False)
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
|
| 204 |
-
st.
|
| 205 |
-
|
| 206 |
|
| 207 |
|
| 208 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import cv2
|
| 2 |
+
import time
|
| 3 |
import tempfile
|
| 4 |
import numpy as np
|
| 5 |
import mediapipe as mp
|
|
|
|
| 47 |
height, width, _ = img.shape
|
| 48 |
for lm in landmarks.landmark:
|
| 49 |
cx, cy = int(lm.x * width), int(lm.y * height)
|
| 50 |
+
cv2.circle(img, (cx, cy), 3, (0, 0, 255), -1)
|
| 51 |
|
| 52 |
for connection in POSE_CONNECTIONS:
|
| 53 |
start_idx, end_idx = connection
|
|
|
|
| 58 |
start_coordinates = (int(start_point.x * width), int(start_point.y * height))
|
| 59 |
end_coordinates = (int(end_point.x * width), int(end_point.y * height))
|
| 60 |
|
| 61 |
+
cv2.line(img, start_coordinates, end_coordinates, (0, 255, 0), 1)
|
| 62 |
|
| 63 |
return img
|
| 64 |
|
|
|
|
| 137 |
|
| 138 |
operation_type = st.radio("Choose operation type", ("Input", "Demo"))
|
| 139 |
|
| 140 |
+
pose = mp_pose.Pose()
|
| 141 |
+
|
| 142 |
if operation_type == "Input":
|
| 143 |
input_type = st.radio("Choose input type", ("Image", "Video"))
|
| 144 |
|
|
|
|
| 155 |
|
| 156 |
draw_box = st.checkbox("Draw bounding box", value=False)
|
| 157 |
|
|
|
|
|
|
|
| 158 |
if uploaded_file is not None:
|
| 159 |
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 160 |
temp_file.write(uploaded_file.read())
|
|
|
|
| 172 |
frame = process_frame(frame, pose, draw_box)
|
| 173 |
|
| 174 |
st_frame.image(frame, channels='BGR', use_column_width=True)
|
| 175 |
+
time.sleep(1)
|
| 176 |
st.empty()
|
| 177 |
|
| 178 |
st.text("Completed")
|
|
|
|
| 188 |
st.empty()
|
| 189 |
st.markdown("<p class='intro'>Demo video will be shown below:</p>", unsafe_allow_html=True)
|
| 190 |
|
| 191 |
+
demo_image_path = "Images/demo.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
image = cv2.imread(demo_image_path)
|
| 194 |
+
processed_image = process_frame(image, pose, draw_box=False)
|
| 195 |
|
| 196 |
+
st.image(processed_image, channels='BGR', use_column_width=True)
|
| 197 |
+
st.text("Done")
|
| 198 |
|
| 199 |
|
| 200 |
if __name__ == "__main__":
|