-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollectdata.py
More file actions
40 lines (34 loc) · 1.19 KB
/
Copy pathcollectdata.py
File metadata and controls
40 lines (34 loc) · 1.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
import cv2
import os
#start video capture
cap = cv2.VideoCapture(0)
#directory to staring the images
directory = 'Image/'
while True:
_, frame = cap.read()
# Dictionary to count nymber of images in each folder
count={
'a': len(os.listdir(directory +'call me')),
'b': len(os.listdir(directory +'good job')),
'c': len(os.listdir(directory +'fuck you')),
}
# Get dimentions of each captured image
row = frame.shape[1]
col = frame.shape[0]
# draw a white rectangel to show capture area
cv2.rectangle(frame, (0,40), (300, 400), (255,255,255), 2)
#display the capture region separately
cv2.imshow('data',frame)
cv2.imshow('ROI', frame[40:400, 0:300])
# crop
frame = frame[40:400, 0:300]
interrupt = cv2.waitKey(10)
if interrupt & 0xFF == ord('a'):
cv2.imwrite(directory + 'call me/' + str(count['a']) + '.png', frame)
if interrupt & 0xFF == ord('b'):
cv2.imwrite(directory + 'good job/' + str(count['b']) + '.png', frame)
if interrupt & 0xFF == ord('c'):
cv2.imwrite(directory + 'fuck you/' + str(count['c']) + '.png', frame)
# Release the video capture device
cap.release()
cv2.destroyAllWindows()