Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,25 @@ model = YOLO("best.pt") # Ensure the path to your model is correct
|
|
| 9 |
# Set the title of the app
|
| 10 |
st.title("Live Fire Detection App")
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
exit()
|
| 17 |
|
| 18 |
while True:
|
|
@@ -28,5 +43,6 @@ while True:
|
|
| 28 |
if cv2.waitKey(1) & 0xFF == ord('q'):
|
| 29 |
break
|
| 30 |
|
|
|
|
| 31 |
cap.release()
|
| 32 |
cv2.destroyAllWindows()
|
|
|
|
| 9 |
# Set the title of the app
|
| 10 |
st.title("Live Fire Detection App")
|
| 11 |
|
| 12 |
+
def capture_video():
|
| 13 |
+
"""Attempts to capture video from the default camera (index 0).
|
| 14 |
|
| 15 |
+
Returns:
|
| 16 |
+
cv2.VideoCapture: The video capture object if successful, None otherwise.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
cap = cv2.VideoCapture(0)
|
| 20 |
+
|
| 21 |
+
if not cap.isOpened():
|
| 22 |
+
print("Error: Could not open video capture device.")
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
return cap
|
| 26 |
+
|
| 27 |
+
# Capture video
|
| 28 |
+
cap = capture_video()
|
| 29 |
+
if cap is None:
|
| 30 |
+
# Handle capture failure gracefully
|
| 31 |
exit()
|
| 32 |
|
| 33 |
while True:
|
|
|
|
| 43 |
if cv2.waitKey(1) & 0xFF == ord('q'):
|
| 44 |
break
|
| 45 |
|
| 46 |
+
# Release resources
|
| 47 |
cap.release()
|
| 48 |
cv2.destroyAllWindows()
|