Repository navigation
Expand file tree
/
Copy pathcollect_imgs.py
More file actions
87 lines (65 loc) · 2.19 KB
/
Copy pathcollect_imgs.py
File metadata and controls
87 lines (65 loc) · 2.19 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os # file handling
import cv2
DATA_DIR = './data'
if not os.path.exists(DATA_DIR):
os.makedirs(DATA_DIR)
# number_of_classes = 3
number_of_classes = 10
dataset_size = 100
# cap = cv2.VideoCapture(2)
cap = cv2.VideoCapture(0)
# Inside data/, it creates folders
for j in range(number_of_classes):
if not os.path.exists(os.path.join(DATA_DIR, str(j))):
os.makedirs(os.path.join(DATA_DIR, str(j)))
print('Collecting data for class {}'.format(j))
# This loop shows the camera feed and waits for the user to press Q
done = False
while True:
ret, frame = cap.read()
cv2.putText(frame, 'Ready? Press "Q" ! :)', (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 255, 0), 3,
cv2.LINE_AA)
cv2.imshow('frame', frame)
if cv2.waitKey(25) == ord('q'):
break
# Start capturing and saving images
counter = 0
while counter < dataset_size:
ret, frame = cap.read()
cv2.imshow('frame', frame)
cv2.waitKey(25)
cv2.imwrite(os.path.join(DATA_DIR, str(j), '{}.jpg'.format(counter)), frame)
counter += 1
cap.release()
cv2.destroyAllWindows()
# import os
# import cv2
# DATA_DIR = './data'
# if not os.path.exists(DATA_DIR):
# os.makedirs(DATA_DIR)
# # number_of_classes = 3
# number_of_classes = 10
# dataset_size = 100
# # cap = cv2.VideoCapture(2)
# cap = cv2.VideoCapture(0)
# for j in range(number_of_classes):
# if not os.path.exists(os.path.join(DATA_DIR, str(j))):
# os.makedirs(os.path.join(DATA_DIR, str(j)))
# print('Collecting data for class {}'.format(j))
# done = False
# while True:
# ret, frame = cap.read()
# cv2.putText(frame, 'Ready? Press "Q" ! :)', (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 255, 0), 3,
# cv2.LINE_AA)
# cv2.imshow('frame', frame)
# if cv2.waitKey(25) == ord('q'):
# break
# counter = 0
# while counter < dataset_size:
# ret, frame = cap.read()
# cv2.imshow('frame', frame)
# cv2.waitKey(25)
# cv2.imwrite(os.path.join(DATA_DIR, str(j), '{}.jpg'.format(counter)), frame)
# counter += 1
# cap.release()
# cv2.destroyAllWindows()