SY-220/Fire_Detection
0
YOLOv8 Fire & Smoke Detection System (with Email Alerts)
A desktop application that downloads a YouTube video, runs YOLOv8-based fire/smoke detection on it frame-by-frame, and optionally sends an email alert — complete with a screenshot of the detected fire — the moment fire is first spotted. Comes with a simple Tkinter GUI so no code editing is required to run it.
Features
- YOLOv8 fire/smoke detection: automatically downloads a dedicated fire-and-smoke YOLOv8 model (falls back to stock
yolov8n.ptif the download fails). - YouTube video input: fetches and processes any YouTube URL via
yt-dlp(with an automatic fallback download strategy if the primary one fails). - Optional email alerts: powered by Resend. When fire is first detected, sends one HTML alert email containing:
- Detection timestamp, video position, fire count, and average confidence
- An embedded screenshot of the exact frame where fire was detected, with the bounding box and warning overlay already drawn on it
- The same screenshot attached as a JPEG file, so it's visible even in email clients that block inline images
- Only one alert is sent per run (no spam on every subsequent detection).
- Tkinter GUI: fill in a YouTube URL, an optional Resend API key, and optional recipient emails — no command-line arguments needed.
- Start / Stop control: detection runs in a background thread so the GUI stays responsive; Stop cleanly interrupts processing after the current frame and still saves everything detected so far.
- CSV detection log: every detection (class, confidence, bounding box, timestamp) is logged to
detection_log.csv, downloadable straight from the GUI via a save-file dialog. - Additional outputs: an annotated output video (
detected_output.mp4), a plain-text fire summary report, and a detailed.txtlog.
How It Works
- Enter a YouTube URL (required) and, optionally, a Resend API key and comma-separated recipient list.
- Click Start Detection. In the background, the app:
- Downloads the video with
yt-dlp. - Loads the YOLOv8 fire/smoke model.
- Steps through the video (every 3rd frame, for speed), running inference and drawing bounding boxes.
- The moment fire is detected, it captures that annotated frame and — if email is configured — sends an alert email with the screenshot embedded and attached.
- Writes an annotated output video and detection logs to
fire_detection_output/. - Click Stop Detection at any time to interrupt processing; partial results are still saved.
- Click Download CSV to save a copy of
detection_log.csvanywhere on disk.
Requirements
opencv-python
yt-dlp
ultralytics
pandas
resendtkinter ships with most standard Python installations (on some Linux distros you may need to install it separately, e.g. sudo apt install python3-tk).
ffmpeg should be available on your PATH for video format conversion in the fallback download path.
Installation
pip install opencv-python yt-dlp ultralytics pandas resendUsage
jupyter YT_fire detection_Resend_GUI_fin.ipynbThis opens the GUI:
Buttons:
- Start Detection / Stop Detection — toggles processing on and off
- Download CSV — saves a copy of the current
detection_log.csvto a location you choose
Note on live preview: unlike a plain OpenCV script, this GUI runs detection headlessly (no cv2.imshow preview window), since mixing an OpenCV GUI window with Tkinter's event loop across threads is unreliable on some platforms. The annotated video is still saved to disk, and progress/results stream into the log panel in real time.Output Files
All outputs are written to fire_detection_output/:
Email Alert Example
When fire is first detected, the alert email includes:
- 🚨 A header banner and detection summary (time, video position, fire count, average confidence)
- 📸 A screenshot of the fire, embedded directly in the email body and attached as
fire_screenshot.jpg - ✅ Recommended next actions (confirm on-site situation, evacuate if necessary, contact the fire department, review the footage)
Limitations
- Detection quality depends entirely on the underlying YOLOv8 fire/smoke model; false positives/negatives are possible, especially with sunset lighting, warm-colored objects, or heavy compression artifacts.
- Only processes pre-recorded YouTube videos, not live streams or local webcams.
- Requires a working internet connection to download the video and model, and to send email alerts.
- Not a certified life-safety system — intended as a demo/prototype for research and educational purposes, not as a replacement for professional fire detection and alarm systems.
- Email sending depends on your Resend account being properly configured (verified sender domain, valid API key, etc.).
License
MIT
