forked from alty619/AI_summer_capstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_extract.py
49 lines (41 loc) · 1.34 KB
/
capture_extract.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
import errno
import cv2
import os
import datetime
from PIL import Image
import time
def recording(cap, fps, codec, start_time, cnt, start_t):
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.flip(frame, 1) # 화면 반전 0: 상하, 1: 좌우
if ret == True:
cv2.imshow('Frame Save', frame)
end_time = datetime.datetime.now()
diff = (end_time - start_time).seconds
if time.time() - start_t >= 3:
cv2.imwrite("./dataset/input%d.jpg" % cnt, frame)
img = cv2.imread("./dataset/input%d.jpg" % cnt)
print("saved image%d.jpg" % cnt)
cnt += 1
start_t = time.time()
if diff > 186: # 3분 동안 웹캠에서 프레임 추출
break
else:
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
try:
if not (os.path.isdir('./dataset')):
os.makedirs('./dataset')
except OSError as e:
if e.errno != errno.EEXIST:
print("Failed to create directory!")
raise
cap = cv2.VideoCapture(0)
fps = 11
codec = cv2.VideoWriter_fourcc(*'DIVX')
cnt = 1
start_time = datetime.datetime.now()
start_t = time.time()
recording(cap, fps, codec, start_time, cnt, start_t)