-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
37 lines (28 loc) · 1.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from ultralytics import YOLO
import cv2
import cvzone
import math
cap = cv2.VideoCapture(0)
cap.set(3, 1024)
cap.set(4, 600)
model = YOLO("best.pt")
classNames = ['Casa Manila', 'Fort Santiago', 'King Charles IV Monument', 'Manila Cathedral', 'Palacio de Gobernador', 'San Agustin Church']
while True:
success, img = cap.read()
results = model(img, stream=True)
for r in results:
boxes = r.boxes
for box in boxes:
# Bounding Box
x1,y1,x2,y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
# cv2.rectangle(img, (x1,y1),(x2,y2),(255,0,255),3)
w, h, = x2 - x1, y2 - y1
cvzone.cornerRect(img,(x1,y1,w,h))
# Confidence
conf = math.ceil((box.conf[0] *100)) / 100
# Class Name
cls = int(box.cls[0])
cvzone.putTextRect(img, f'{classNames[cls]} {conf}', (max(0, x1), max(35, y1)),scale=0.9,thickness=2)
cv2.imshow("Image",img)
cv2.waitKey(1)