File size: 1,306 Bytes
4e84bac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import streamlit as st
import cv2
from ultralytics import YOLO
import tempfile
import os
# Load YOLOv8 pose model
model = YOLO("yolo11x-pose.pt")
st.title("🕺 Pose Detection with YOLOv8")
# File uploader
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Save uploaded file to a temp folder manually
temp_dir = tempfile.gettempdir()
file_path = os.path.join(temp_dir, uploaded_file.name)
with open(file_path, "wb") as f:
f.write(uploaded_file.read())
# Run inference
results = model(file_path)
for r in results:
# Get annotated frame
annotated_frame = r.plot()
# Convert BGR → RGB for Streamlit
annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
# Show output
st.image(annotated_frame, caption="Pose Detection Result", use_container_width=True)
# Optional: save & download
output_path = os.path.join(temp_dir, "pose_output.jpg")
cv2.imwrite(output_path, r.plot())
with open(output_path, "rb") as file:
st.download_button(
label="Download Result",
data=file,
file_name="pose_detection.jpg",
mime="image/jpeg"
)
|