-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGray_Capture_Convertor.py
More file actions
58 lines (50 loc) · 2.05 KB
/
Gray_Capture_Convertor.py
File metadata and controls
58 lines (50 loc) · 2.05 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
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 12:29:45 2020
REQUIREMENTS:-
You need to press 's' (on keyboard) for conversion and capture of 28x28 image conversion.
One would require DLIB for image recognition, on which I am working.
Here is the basic code or skeleton of our project for detection purposes only.
"""
import cv2
key = cv2. waitKey(1)
cam = cv2.VideoCapture(0)
while True:
try:
check, frame = cam.read()
print(check) #prints true as long as the cam is running
print(frame) #prints matrix values of each framecd
cv2.imshow("Capturing", frame)
key = cv2.waitKey(1)
if key == ord('s'): #Keyboard input 's' saves an image
cv2.imwrite(filename='new_gray_saved_img.jpg', img=frame)
cam.release()
img_new = cv2.imread('new_gray_saved_img.jpg', cv2.IMREAD_GRAYSCALE) #Read and grayscale conversion
img_new = cv2.imshow("Captured Image", img_new) #Show image
cv2.waitKey(1650) #sleep functionality equivalent
cv2.destroyAllWindows()
print("Processing image...")
img_ = cv2.imread('new_gray_saved_img.jpg', cv2.IMREAD_ANYCOLOR)
print("Converting RGB image to grayscale...")
gray = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY)
print("Converted RGB image to grayscale...")
print("Resizing image to 28x28 scale...")
img_ = cv2.resize(gray,(28,28))
print("Resized...")
img_resized = cv2.imwrite(filename='gray_saved_img-final.jpg', img=img_)
print("Image saved!")
break
elif key == ord('q'):
print("Turning off camera.")
cam.release()
print("Camera off.")
print("Program ended.")
cv2.destroyAllWindows()
break
except(KeyboardInterrupt):
print("Turning off camera.")
cam.release()
print("Camera off.")
print("Program ended.")
cv2.destroyAllWindows()
break