A collection of Python scripts for experimenting with YOLO (You Only Look Once) models for various computer vision tasks including object detection and pose estimation.
This repository contains implementations for running YOLO models on different input sources (images, webcam, phone camera) with support for object detection, pose estimation, and instance segmentation tasks. Includes both command-line scripts and an interactive Streamlit web application for easy experimentation.
yolo-experiment/
├── app.py # Streamlit web application
├── object-detection/ # Object detection scripts
│ ├── image.py # Process static images
│ ├── webcam.py # Webcam stream detection
│ └── phone.py # Phone camera stream detection
├── pose-estimation/ # Pose estimation scripts
│ └── webcam_pose.py # Real-time pose estimation
├── data/ # Input data directory
├── output/ # Output directory for results
├── *.pt # Pre-trained YOLO model weights
└── requirements.txt # Python dependencies
The repository includes several pre-trained YOLO model weights:
Object Detection Models:
yolov8n.pt- YOLOv8 Nanoyolov8m-oiv7- YOLOv8 Medium trained on Open Images V7yolo12n.pt- YOLO12 Nano
Pose Estimation Models:
yolov8n-pose.pt- YOLOv8 Nano Poseyolo11n-pose.pt- YOLO11 Nano Pose
Instance Segmentation Models:
yolov8n-seg.pt- YOLOv8 Nano Segmentationyolo11n-seg.pt- YOLO11 Nano Segmentation
- Clone the repository:
git clone <repository-url>
cd yolo-experiment- Install dependencies:
pip install -r requirements.txt- ultralytics
- opencv-python
- pillow
- streamlit (required for the web application)
Process a single image with YOLO object detection:
python object-detection/image.py- Place your input image at
data/image.jpg - Output will be saved to
data/output.jpg - Displays detection results in a window
Real-time object detection using your computer's webcam:
python object-detection/webcam.pyFeatures:
- Real-time object detection with threading for optimal performance
- FPS counter overlay
- Automatic video recording to
output/webcam/recording_<timestamp>.mp4 - Press 'q' to quit
Stream and detect objects from your phone camera:
python object-detection/phone.pyFeatures:
- Connects to phone camera via IP webcam app (default:
https://192.168.20.19:8080/video) - Multi-threaded frame capture for reduced latency
- Frame rotation support (configurable via
rotvariable) - Saves recording to
output/phone/recording_<timestamp>.mp4 - Press 'q' to quit
Setup:
- Install an IP webcam app on your phone (e.g., "IP Webcam" for Android)
- Update the
phone_urlvariable inphone.pywith your phone's IP address - Ensure phone and computer are on the same network
Real-time human pose estimation using your webcam:
python pose-estimation/webcam_pose.pyFeatures:
- Detects 17 body keypoints (nose, eyes, ears, shoulders, elbows, wrists, hips, knees, ankles)
- Real-time FPS display
- Press 'q' to quit
Interactive web-based interface for running YOLO models with real-time webcam processing:
streamlit run app.pyFeatures:
- Web-based UI accessible via browser
- Three application modes:
- Object Detection - Detect and classify objects in real-time
- Pose Recognition - Track human body keypoints
- Instance Segmentation - Segment and identify individual object instances
- Configurable settings via sidebar:
- Model selection (mode-specific models available)
- Confidence threshold slider (0.0-1.0)
- IoU (Intersection over Union) threshold slider (0.0-1.0)
- Real-time webcam stream processing
- Live preview of processed frames
Available Models:
- Object Detection:
yolo12n.pt,yolov8n.pt,yolov8m-oiv7 - Pose Recognition:
yolo11n-pose.pt,yolov8n-pose.pt - Instance Segmentation:
yolo11n-seg.pt,yolov8n-seg.pt
Requirements: In addition to the base requirements, you'll need:
pip install streamlitThe app automatically opens in your default browser at http://localhost:8501
Each script uses a specific YOLO model. To change the model, edit the model initialization line:
model = YOLO("yolov8n.pt") # Change to desired modelAdjust the confidence threshold in the detection scripts:
results = model(frame, conf=0.5) # Change conf value (0.0-1.0)To detect specific object classes only (see webcam.py example):
results = model(frame, conf=0.5, classes=[41, 45, 64, 66]) # Cup, bowl, keyboard, mouseThe webcam and phone camera scripts use threading to separate frame capture from inference, reducing latency and improving FPS. Key optimizations:
- Frame queue with max size 2 to prevent buffering lag
- Separate capture thread for continuous frame grabbing
- Minimal buffer size in OpenCV capture
See LICENSE file for details.