-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaptue_images.py
64 lines (51 loc) · 1.6 KB
/
Captue_images.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
63
64
import cv2
import numpy as np
import os
import time
cap = cv2.VideoCapture(1)
def capture_webcam ():
global cap
#ret = cap.set(cv.CAP_PROP_FRAME_WIDTH, 320)
#ret = cap.set(cv.CAP_PROP_FRAME_HEIGHT, 240).
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(width, height)
if cap.isOpened():
ret, rgb_frame = cap.read()
if ret is False:
rgb_frame = np.zeros((width, height, 3), np.uint8)
else:
width = 224
height = 224
rgb_frame = np.zeros((width, height, 3), np.uint8)
gray_frame = cv2.cvtColor(rgb_frame, cv2.COLOR_BGR2GRAY)
return rgb_frame, gray_frame
label = '33'
path = './images/'
i = 199
cnt = 199
for i in range(200, 400):
data = capture_webcam()
cnt = str(i)
rgb = os.path.join(path + '/rgb/' + label)
gray = os.path.join(path + '/gray/' + label)
cv2.imwrite(os.path.join(rgb, 'IMG' + cnt + '.jpg'), data[0])
cv2.imwrite(os.path.join(gray, 'IMG' + cnt + '.jpg'), data[1])
time.sleep(0.15)
#cv2.imshow('test', data[0])
#cv2.imshow('test2', data[1])
print('______________________________________')
time.sleep(5)
i = 100
for i in range(400, 600):
data = capture_webcam()
cnt = str(i)
rgb = os.path.join(path + '/rgb/' + label)
gray = os.path.join(path + '/gray/' + label)
cv2.imwrite(os.path.join(rgb, 'IMG' + cnt + '.jpg'), data[0])
cv2.imwrite(os.path.join(gray, 'IMG' + cnt + '.jpg'), data[1])
time.sleep(0.15)
#cv2.imshow('test', data[0])
#cv2.imshow('test2', data[1])
print('finished')
cap.release()