ArchiMathur commited on
Commit
d135789
·
verified ·
1 Parent(s): 0f89eeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -10
app.py CHANGED
@@ -2,25 +2,55 @@ import streamlit as st
2
  import cv2
3
  import numpy as np
4
  from ultralytics import YOLO
 
 
5
 
6
- # Load the YOLO model
7
- model = YOLO("best.pt") # Ensure the path to your model is correct
8
 
9
- # Set the title of the app
10
- st.title("Live Fire Detection App")
11
  cap = cv2.VideoCapture(0)
12
  cap.set(3, 640)
13
  cap.set(4, 480)
14
 
 
 
 
 
15
  while True:
16
- ret, img= cap.read()
17
- cv2.imshow('Webcam', img)
18
 
19
- if cv2.waitKey(1) == ord('q'):
20
- break
 
21
 
22
- cap.release()
23
- cv2.destroyAllWindows()
 
 
 
 
 
 
 
 
 
24
 
 
 
 
25
 
 
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
2
  import cv2
3
  import numpy as np
4
  from ultralytics import YOLO
5
+ import math
6
+
7
 
 
 
8
 
9
+ # start webcam
 
10
  cap = cv2.VideoCapture(0)
11
  cap.set(3, 640)
12
  cap.set(4, 480)
13
 
14
+ # Load the YOLO model
15
+ model = YOLO("best.pt") # Ensure the path to your model is correct
16
+
17
+
18
  while True:
19
+ success, img = cap.read()
20
+ results = model(img, stream=True)
21
 
22
+ # coordinates
23
+ for r in results:
24
+ boxes = r.boxes
25
 
26
+ for box in boxes:
27
+ # bounding box
28
+ x1, y1, x2, y2 = box.xyxy[0]
29
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) # convert to int values
30
+
31
+ # put box in cam
32
+ cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 3)
33
+
34
+ # confidence
35
+ confidence = math.ceil((box.conf[0]*100))/100
36
+ print("Confidence --->",confidence)
37
 
38
+ # class name
39
+ cls = int(box.cls[0])
40
+ print("Class name -->", classNames[cls])
41
 
42
+ # object details
43
+ org = [x1, y1]
44
+ font = cv2.FONT_HERSHEY_SIMPLEX
45
+ fontScale = 1
46
+ color = (255, 0, 0)
47
+ thickness = 2
48
 
49
+ cv2.putText(img, classNames[cls], org, font, fontScale, color, thickness)
50
+
51
+ cv2.imshow('Webcam', img)
52
+ if cv2.waitKey(1) == ord('q'):
53
+ break
54
+
55
+ cap.release()
56
+ cv2.destroyAllWindows()