-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse_callback.py
66 lines (51 loc) · 1.84 KB
/
mouse_callback.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
63
64
65
66
from audioop import reverse
import cv2 as cv
import numpy as np
from constant import *
from _utils import *
def handle_left_click(event, x, y,flags, points):
if event == cv.EVENT_LBUTTONDOWN:
points.append([x, y])
# return points
def polygon_callback(filename):
points = []
video = cv.VideoCapture(filename)
fill = False
while True:
ret, frame = video.read()
frame = cv.resize(frame, IMG_SIZE)
frame = draw_polylines(frame, points)
cv.imshow('video', frame)
# Nếu kích chuột trái thì lấy điểm theo tọa độ x,y vào thêm vào mảng point
cv.setMouseCallback('video', handle_left_click, points)
key = cv.waitKey(10)
if key == ord('q'):
break
if key == ord('d'):
points.append(points[0])
video.release()
cv.destroyAllWindows()
return points
def line_callback(filename):
points = []
video = cv.VideoCapture(filename)
fill = False
while True:
ret, frame = video.read()
frame = cv.resize(frame, (IMG_SIZE))
frame = draw_polylines(frame, points)
cv.imshow('video', frame)
if len(points) < 3:
# Nếu kích chuột trái thì lấy điểm theo tọa độ x,y vào thêm vào mảng point
cv.setMouseCallback('video', handle_left_click, points)
key = cv.waitKey(10)
if key == ord('q'):
break
video.release()
cv.destroyAllWindows()
return points
if __name__ =="__main__":
points = polygon_callback(VIDEO_PATH)
np.savetxt(POLYGON_PATH, points, delimiter = ' ', fmt = '%s')
# points = line_callback(VIDEO_PATH)
# np.savetxt(LINE_PATH, points, delimiter = ' ', fmt = '%s')