-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (42 loc) · 1.19 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
from ultralytics import YOLOv10
import pandas as pd
import cvzone
model = YOLOv10("best.pt")
def RGB(event, x, y, flags, param):
if event == cv2.EVENT_MOUSEMOVE:
point = [x, y]
print(point)
cv2.namedWindow('RGB')
cv2.setMouseCallback('RGB', RGB)
cap = cv2.VideoCapture('drivingrules.mp4')
my_file = open("coco1.txt", "r")
data = my_file.read()
class_list = data.split("\n")
count = 0
while True:
ret, frame = cap.read()
count += 1
if count % 3 != 0:
continue
if not ret:
break
frame = cv2.resize(frame, (1020, 600))
results = model(frame)
a = results[0].boxes.data
px = pd.DataFrame(a).astype("float")
for index, row in px.iterrows():
x1 = int(row[0])
y1 = int(row[1])
x2 = int(row[2])
y2 = int(row[3])
d = int(row[5])
c = class_list[d]
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cvzone.putTextRect(frame, f'{c}', (x1, y1), 1, 1)
cv2.imshow("RGB", frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()