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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -9,32 +9,24 @@ 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
- # Define color ranges for fire detection
13
- lower_red = np.array([0, 100, 100])
14
- upper_red = np.array([10, 255, 255])
15
 
16
- # Create a video capture object
17
- cap = cv2.VideoCapture(0) # 0 for default camera, change as needed
 
18
 
19
  while True:
20
  ret, frame = cap.read()
21
 
22
- # Convert BGR to HSV color space
23
- hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
24
-
25
- # Create a mask for the fire color range
26
- mask = cv2.inRange(hsv, lower_red, upper_red)
27
-
28
- # Apply the mask to the original frame
29
- res = cv2.bitwise_and(frame, frame, mask=mask)
30
 
31
- # Display the resulting frame
32
- cv2.imshow('Fire Detection', res)
33
 
34
- # Exit if 'q' is pressed
35
  if cv2.waitKey(1) & 0xFF == ord('q'):
36
  break
37
 
38
- # Release the capture and close windows
39
  cap.release()
40
- cv2.destroyAllWindows() 1
 
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:
19
  ret, frame = cap.read()
20
 
21
+ if not ret:
22
+ print("Error: Could not read frame.")
23
+ break
 
 
 
 
 
24
 
25
+ # Process the frame here (e.g., display, save, analyze)
26
+ cv2.imshow('Frame', frame)
27
 
 
28
  if cv2.waitKey(1) & 0xFF == ord('q'):
29
  break
30
 
 
31
  cap.release()
32
+ cv2.destroyAllWindows()