fireDetection / app.py
ArchiMathur's picture
Update app.py
5b83d94 verified
Raw
History Blame
1.02 kB
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")
def capture_video():
"""Attempts to capture video from the default camera (index 0).
Returns:
cv2.VideoCapture: The video capture object if successful, None otherwise.
"""
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open video capture device.")
return None
return cap
# Capture video
cap = capture_video()
if cap is None:
# Handle capture failure gracefully
exit()
while True:
ret, frame = cap.read()
if not ret:
print("Error: Could not read frame.")
break
# Process the frame here (e.g., display, save, analyze)
cv2.imshow('Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release resources
cap.release()
cv2.destroyAllWindows()