forked from Dohyeon-Kim1/Mutimodal-CCTV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (45 loc) · 1.38 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
55
56
57
58
59
60
61
62
import requests
import threading
import cv2
from ultralytics import YOLO
current_frames = []
current_caption = ""
def post_frames():
global current_caption
frames = current_frames[0]
response = requests.post(
"http://127.0.0.1:5001/receive",
json={"frames": frames}
)
current_caption = response.json()["caption"]
threading.Timer(4, post_frames).start()
def main():
yolo = YOLO("yolo_cctv.pt")
cap = cv2.VideoCapture(1)
if not cap.isOpened():
print("웹캠을 열 수 없습니다.")
return
processed_frames = 0
max_ref_frame = 8
post_frames()
while True:
ret, frame = cap.read()
if not ret:
print("프레임을 가져올 수 없습니다.")
break
else:
processed_frames += 1
if processed_frames % 5 == 0:
if len(current_frames) == max_ref_frame:
current_frames.pop(0)
current_frames.append(frame)
results = yolo.predict(frame, imgsz=640, augment=False, show=False)
annotated_frame = results[0].plot()
# 화면에 표시
cv2.imshow("YOLO Real-time Detection", annotated_frame)
print(current_caption)
# ESC 키(27번) 누르면 종료
if cv2.waitKey(1) & 0xFF == 27:
break
if __name__ == "__main__":
main()