Devlog #13 : built a fire detection system for my drone’s Pi
i genuinely lost my sanity working on ts
(Everything is on gh)
started on the payload for my autonomous quad: real time fire detection running on the Raspberry Pi.
went classical CV with OpenCV instead of training a model. Since it has to run fully offline on the drone (no internet up there) so a heavy ML model was out. turns out you get pretty far with just color + motion.
how it works:
- grabs the warm/bright pixels (orange/red/yellow in HSV, plus an R≥G≥B rule so it’s actually fire toned, not just bright)
-
flicker analysis over a few frames. ts is the part that matters. real flame shimmers frame to frame, a static orange thing (a ball, a jacket, a sunset) doesn’t, so it won’t false trigger on every orange object it sees
- debounces over several frames so one noisy frame can’t trip it
- spits out a 0-100% confidence from area + flicker + persistence
the two bits that do the work. color mask first:
# warm/bright flame colors
warm = cv2.inRange(hsv, (0, sat_min, val_min), (35, 255, 255))
warm |= cv2.inRange(hsv, (170, sat_min, val_min), (179, 255, 255))
# fire skews R >= G >= B with a real red lead, not just any bright pixel
b, g, r = cv2.split(bgr.astype(np.int16))
order = ((r >= g) & (g >= b) & (r > 150) & ((r - b) > 28)).astype(np.uint8) * 255
warm = cv2.bitwise_and(warm, order)
then the flicker check. just how much the fire region changed since last frame:
diff = cv2.absdiff(mask, prev_mask)
flicker = np.count_nonzero(diff) / max(fire_area, 1)
# static orange object -> ~0 real flame -> way higher
built a web dashboard for it too (Flask). same code runs on my laptop off the webcam to test, then goes straight on the Pi headless and i open it from my laptop browser over wifi. console sits calm/cyan while scanning, goes full red + pulsing + beeping the sec it locks fire. got live sliders to tune sensitivity so i’m not editing code every time.
tested 4k fireplace video, locks on clean. waved random orange stuff
it’s not certified or anything. classical CV WILL false trigger in harsh light so
next: wire the “fire detected” event to grab the GPS coord off the flight controller and trigger a loiter so the drone marks the spot.
btw if anyone’s done fire/smoke detection on a Pi 4 lmk if you went CV or tflite, curious what fps you got. 🫡