-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (40 loc) · 1.24 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
import cv2
import numpy as np
from imutils.video import filevideostream
from yolodetect import YoloDetect
# Chua cac diem nguoi dung chon de tao da giac
points = []
# new model Yolo
model = YoloDetect()
def handle_left_click(event, x, y, flags, points):
if event == cv2.EVENT_LBUTTONDOWN:
points.append([x, y])
def draw_polygon(frame, points):
for point in points:
frame = cv2.circle( frame, (point[0], point[1]), 5, (0,0,255), -1)
# print(points)
frame = cv2.polylines(frame, [np.int32(points)], False, (255,0, 0), thickness=2)
return frame
detect = False
path = 'bienso.mp4'
cap = cv2.VideoCapture(path)
while(cap.isOpened()):
ret, frame = cap.read()
if ret ==True:
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = draw_polygon(frame, points)
if detect:
frame = model.detect(frame,points)
key = cv2.waitKey(1)
if key == ord('q'):
break
elif key == ord('d'):
points.append(points[0])
detect = True
cv2.imshow("Intrusion Warning", frame)
cv2.setMouseCallback('Intrusion Warning', handle_left_click, points)
else:
break
# Hien anh ra man hinh
cap.release()
cv2.destroyAllWindows()