File size: 1,013 Bytes
defef4e
42df645
defef4e
42df645
 
 
 
 
0be7ae3
42df645
0be7ae3
a80de8b
 
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
0be7ae3
a80de8b
 
 
0be7ae3
a80de8b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
import cv2
import numpy as np
from ultralytics import YOLO

# Load the YOLO model
model = YOLO("best.pt")  # Ensure the path to your model is correct

# Set the title of the app
st.title("Live Fire Detection App")

# Define color ranges for fire detection
lower_red = np.array([0, 100, 100])
upper_red = np.array([10, 255, 255])

# Create a video capture object
cap = cv2.VideoCapture(0)  # 0 for default camera, change as needed

while True:
    ret, frame = cap.read()

    # Convert BGR to HSV color space
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    # Create a mask for the fire color range
    mask = cv2.inRange(hsv, lower_red, upper_red)

    # Apply the mask to the original frame
    res = cv2.bitwise_and(frame, frame, mask=mask)

    # Display the resulting frame
    cv2.imshow('Fire Detection', res)

    # Exit if 'q' is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the capture and close windows
cap.release()
cv2.destroyAllWindows() 1