ArchiMathur commited on
Commit
5b83d94
·
verified ·
1 Parent(s): cb01c7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
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
- cap = cv2.VideoCapture(0) # 0 for default camera
 
13
 
14
- if not cap.isOpened():
15
- print("Error: Could not open video capture device.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()