-
Notifications
You must be signed in to change notification settings - Fork 4
/
VideoMarker.py
71 lines (52 loc) · 1.74 KB
/
VideoMarker.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
67
68
69
70
71
'''
USAGE
python VideoMarker.py FolderWithImages OutputFileName
NOTE : LEFT CLICK for one end and RIGHT CLICK for the other
Keep pressing ENTER to continue. If you want to stop at the middle press 'q'
LOADING
numpy.load(OutputFileName.npy)
'''
import argparse
import sys
import os
import cv2
import numpy as np
def mouse_callback(event, x, y, flags, param):
global frame
if event == cv2.EVENT_RBUTTONDOWN:
points[2], points[3] = x, y
frame1 = np.array(frame, copy=True)
cv2.rectangle(frame1,(points[0],points[1]),(points[2],points[3]),(0,255,0),3)
cv2.imshow('frame', frame1)
# print(x, y, points)
if event == cv2.EVENT_LBUTTONDOWN:
points[0], points[1] = x, y
frame1 = np.array(frame, copy=True)
cv2.rectangle(frame1,(points[0],points[1]),(points[2],points[3]),(0,255,0),3)
cv2.imshow('frame', frame1)
# print(x, y, points)
if __name__ == "__main__":
FILE_NAME=sys.argv[1]
cv2.namedWindow('frame')
cv2.setMouseCallback('frame', mouse_callback)
cap = cv2.VideoCapture(FILE_NAME)
ans = []
points = [0, 0, 0, 0]
while (1):
ret, frame = cap.read()
if ret == True:
frame1 = np.array(frame, copy = True)
cv2.rectangle(frame1, (points[0], points[1]), (points[2], points[3]), (0, 255, 0), 2)
cv2.imshow('frame', frame1)
k = cv2.waitKey(0) & 0xff
if k == ord('q'):
break
print (points)
x1, y1, x2, y2 = points
points[0] = min(x1, x2)
points[1] = min(y1, y2)
points[2] = max(x1, x2)
points[3] = max(y1, y2)
ans.append(points)
print("Saved")
np.save(sys.argv[2], ans)