-
Notifications
You must be signed in to change notification settings - Fork 1
/
collector.py
48 lines (32 loc) · 1.07 KB
/
collector.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
print('[collector.py] Initiating script - Image Collector')
import cv2 #opencv
import os
import time
import uuid
IMG_PATH = 'Tensorflow/workspace/images/collectedImages'
labels = ['hello', 'thanks', 'yes', 'no', 'iloveyou']
imgQtd = 15
#
print('[collector.py] Preparing capture')
cap = cv2.VideoCapture(0)
for label in labels:
newdirpath = os.path.join('Tensorflow', 'workspace', 'images', 'collectedImages', label)
if not os.path.exists(newdirpath):
print('[collector.py] Created new directory: {}'.format(newdirpath))
os.mkdir(newdirpath)
print('[collector.py] Collecting images for {}'.format(label))
time.sleep(5)
count = 1
for imgnum in range(imgQtd):
ret, frame = cap.read()
imgname = label + '.' + '{}.jpg'.format(str(uuid.uuid1()))
newimgpath = os.path.join(IMG_PATH, label, imgname)
cv2.imwrite(newimgpath, frame)
cv2.imshow('Frame', frame)
time.sleep(2)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
count += 1
print('[collector.py] Finished collecting images!')
cap.release()
cv2.destroyAllWindows()