This is a simple fire detector that was written using python. It requires OpenCV and Numpy. The program works by taking in a video and processing the video frame by frame. It switches the color space to HSV. HSV is more similar to the way humans perceive color than the default RGB color space. Next, upper and lower color values are defined. A mask is applied to the  frame and only the colors in the range we defined are visible.

It is a simple program. I’ve seen similar methods used to detect road lanes for self driving cars.

If you have any questions feel free to ask them in the comments below.

import cv2
import numpy as np

video_file = "video_1.mp4"
video = cv2.VideoCapture(video_file)

while True:
    (grabbed, frame) = video.read()
    if not grabbed:
        break

    blur = cv2.GaussianBlur(frame, (21, 21), 0)
    hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)

    lower = [18, 50, 50]
    upper = [35, 255, 255]
    lower = np.array(lower, dtype="uint8")
    upper = np.array(upper, dtype="uint8")
    mask = cv2.inRange(hsv, lower, upper)


    output = cv2.bitwise_and(frame, hsv, mask=mask)
    cv2.imshow("output", output)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()
video.release()