This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_labeler.py
62 lines (43 loc) · 1.58 KB
/
main_labeler.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
#!/usr/bin/env python3
import os
import cv2
def label_video(video_dir, video_filename, label_file):
video_path = os.path.join(video_dir, video_filename)
print('Opening {}...'.format(video_path))
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print('Error')
frame_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
frame_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print('frame_width = {}'.format(frame_width))
print('frame_height = {}'.format(frame_height))
print('fps = {}'.format(fps))
label_file.write('frame,timestamp,entered,left\n')
count = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
pos_ms = cap.get(cv2.CAP_PROP_POS_MSEC)
pos_frames = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
"""
if pos_frames % 100 == 0:
frame_path = os.path.join(video_dir, 'frame-{:05}.jpg'.format(pos_frames))
cv2.imwrite(frame_path, frame)
"""
cv2.imshow('frame', frame)
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
has_entered = 1 if key == ord('e') else 0
has_left = 1 if key == ord('l') else 0
label_file.write('{},{},{},{}\n'.format(pos_frames, pos_ms, has_entered, has_left))
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
label_filename = 'gate1.csv'
video_dir = 'new_videos/'
video_filename = 'gate1.mp4'
with open(label_filename, 'w') as f:
label_video(video_dir, video_filename, f)