-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimg_capture.py
69 lines (58 loc) · 2.16 KB
/
img_capture.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
65
66
67
68
69
import cv2
import os
def capture_image(uid):
# Detects key press in milliseconds
key = cv2. waitKey(1)
# Start webcam and configure options
webcam = cv2.VideoCapture(0,cv2.CAP_DSHOW)
webcam.set(cv2.CAP_PROP_FRAME_WIDTH, 400)
webcam.set(cv2.CAP_PROP_FRAME_HEIGHT, 400)
# Placeholder name for images
img_name = 'customer_images/'+str(uid)+'.jpg'
while True:
check, frame = webcam.read()
cv2.imshow('Capturing Image......', frame)
key = cv2.waitKey(1)
# Capture image and convert it to grayscale and resize on pressing 'C'
if key == ord('c'):
cv2.imwrite(filename=img_name, img=frame)
_img = cv2.imread(img_name, cv2.IMREAD_ANYCOLOR)
# gray = cv2.cvtColor(_img, cv2.COLOR_BGR2GRAY)
img_resize = cv2.resize(_img, (256, 256))
img_resized = cv2.imwrite(
filename=img_name, img=img_resize)
break
webcam.release()
cv2.destroyAllWindows()
def capture_recognition_image():
print('---------')
# Detects key press in milliseconds
key = cv2. waitKey(1)
# Start webcam and configure options
webcam = cv2.VideoCapture(0,cv2.CAP_DSHOW)
webcam.set(cv2.CAP_PROP_FRAME_WIDTH, 400)
webcam.set(cv2.CAP_PROP_FRAME_HEIGHT, 400)
# Placeholder name for images
img_name = 'test_image.jpg'
while True:
check, frame = webcam.read()
cv2.imshow('Capturing Test Image......', frame)
key = cv2.waitKey(1)
# Capture image and convert it to grayscale and resize on pressing 'C'
if key == ord('c'):
cv2.imwrite(filename=img_name, img=frame)
_img = cv2.imread(img_name, cv2.IMREAD_ANYCOLOR)
# gray = cv2.cvtColor(_img, cv2.COLOR_BGR2GRAY)
img_resize = cv2.resize(_img, (256, 256))
img_resized = cv2.imwrite(
filename=img_name, img=img_resize)
break
webcam.release()
cv2.destroyAllWindows()
# Delete images after transaction
def delete_faces():
images = os.listdir('customer_faces')
os.remove('test_image.jpg')
for image in images:
delete_path = 'customer_faces/'+image
os.remove(delete_path)