An intelligent lighting control system that uses YOLOv8 object detection to automatically adjust light brightness based on detected objects in a camera stream. The system can distinguish between people (triggers lights) and smaller objects like birds (ignored).
- π― Real-time Object Detection using YOLOv8
- πΉ Multiple Camera Sources support (webcam, IP cameras, RTSP, HTTP streams)
- π‘ Intelligent Light Control based on object size and type
- π§ FastAPI REST API for control and monitoring
- βοΈ Configurable Thresholds for object filtering
- ποΈ Smooth Transitions with debouncing to prevent flickering
- π Real-time Monitoring via API endpoints
- Object Detection: YOLOv8 (Ultralytics)
- API Framework: FastAPI
- Computer Vision: OpenCV
- Configuration: YAML
Prerequisites:
- Docker Desktop installed (Download)
For Team Members - Pull Pre-built Image:
# Pull the latest image
docker pull rs735my/smart-lighting-detection:latest
# Run with docker-compose
docker-compose upThe application will be available at http://localhost:8000
Note: USB webcams don't work in Docker on Windows. Use IP camera, RTSP stream, or video file. Edit config.yaml:
camera:
source: "http://192.168.1.100:8080/video" # IP Webcam from phone
# OR
source: "/app/videos/sample.mp4" # Video fileFor Developers - Build Locally:
# Build and run
docker-compose up --build
# Or build without running
docker build -t smart-lighting-detection .-
Clone or navigate to the project directory
-
Create a virtual environment:
python -m venv venv .\venv\Scripts\Activate.ps1 -
Install dependencies:
pip install -r requirements.txt -
Set camera source in
config.yaml:camera: source: "0" # USB webcam works with native Python
Edit config.yaml to customize:
- Camera source (webcam, IP camera URL, video file)
- Detection settings (model type, confidence threshold, target classes)
- Object size filtering (min/max bounding box area)
- Light control (brightness levels, fade duration, auto-off delay)
- Lighting backend (simulated, MQTT, HTTP, Philips Hue)
python main.pyThe API will be available at: http://localhost:8000
- GET
/- API information - GET
/status- Get current system status - POST
/start- Start video processing - POST
/stop- Stop video processing - GET
/stream- Live video stream with detections - POST
/config- Update configuration - GET
/lights/status- Get current light status - POST
/lights/manual- Manually control lights
Visit http://localhost:8000/docs for Swagger UI documentation.
- Video Capture: Fetches frames from configured camera source
- Object Detection: YOLOv8 analyzes each frame and detects objects
- Filtering: Filters objects by class (person) and size (area > threshold)
- Light Control: Adjusts light brightness based on detected objects
- Debouncing: Prevents rapid on/off switching with configurable delays
camera:
source: "0"camera:
source: "rtsp://username:password@192.168.1.100:554/stream"camera:
source: "http://192.168.1.100:8080/video"detection:
confidence: 0.6 # Higher = more strict
min_object_size: 10000 # Larger = only bigger objectslighting:
mode: "simulated"lighting:
mode: "mqtt"
mqtt:
broker: "192.168.1.100"
topic: "home/lights/control"lighting:
mode: "http"
http:
url: "http://your-light-api.com/control"- Verify camera URL/source in
config.yaml - Check network connectivity
- Test with webcam (
source: "0") first
- Lower
confidencethreshold in config - Verify camera has clear view
- Check
target_classesincludes "person"
- Verify
lighting.modeis configured correctly - Check connection to light control system
- Test with
mode: "simulated"first
When you add new dependencies or make changes:
-
Update
requirements.txtwith new packages:pip freeze > requirements.txt -
Rebuild the Docker image:
docker-compose build --no-cache
-
Tag the new version:
docker tag tmovprojekt-object-detection:latest rs735my/smart-lighting-detection:latest # Or with version number docker tag tmovprojekt-object-detection:latest rs735my/smart-lighting-detection:v1.1
-
Push to Docker Hub:
# Login first (if not already) docker login # Push latest docker push rs735my/smart-lighting-detection:latest # Also push versioned tag (recommended) docker push rs735my/smart-lighting-detection:v1.1
-
Notify team members to pull the new image:
docker-compose pull docker-compose up
-
Install package locally:
pip install package-name -
Update requirements.txt:
pip freeze > requirements.txt -
Rebuild and push Docker image (steps above)
.
βββ main.py # FastAPI application entry point
βββ detector.py # YOLOv8 object detection
βββ camera.py # Camera stream handling
βββ light_controller.py # Light control logic
βββ video_processor.py # Video processing service
βββ config.yaml # Configuration file
βββ requirements.txt # Python dependencies
βββ README.md # This file
MIT License
- Web dashboard for monitoring
- Multiple camera support
- Zone-based detection
- Activity logging and analytics
- Mobile app integration
- Advanced scheduling rules