Spaces:
Runtime error
Runtime error
| 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 | |