-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (71 loc) · 2.51 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import cv2
import imghdr
import tensorflow as tf
import modelFuncs
import numpy as np
from tensorflow.keras.models import load_model
from matplotlib import pyplot as plt
def takePic():
cap = cv2.VideoCapture(0)
i = 1
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Operations on the frame
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('Webcam Feed', gray_frame)
# Save required number of images
if i < 3 and i != 1:
img_name = 'imageForUse' + str(i) + '.png'
cv2.imwrite(img_name, gray_frame)
i = i + 1
if i > 3 or (cv2.waitKey(1) & 0xFF == ord('q')):
break
# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
return 'imageForUse' + str(i) + '.png'
def main():
takeNewPic = input("Take a new photo (Y) or enter filename (N) : ")
if takeNewPic[0] in ['y', 'Y']:
takePic()
img = cv2.imread('imageForUse2.png')
resize = tf.image.resize(img, (256,256))
new_model = load_model('models/imageclassifier.h5')
emotion_prediction = new_model.predict(np.expand_dims(resize/255, 0))
if emotion_prediction > 0.5:
print(f'Predicted classification is Sad')
print(emotion_prediction)
plt.imshow(img)
plt.suptitle('This person is Sad 😢' )
plt.show()
else:
print(f'Predicted classification is Happy')
print(emotion_prediction)
plt.imshow(img)
plt.suptitle('This person is Happy 😁' )
plt.show()
return
# Load image
#img = cv2.imread('web3-happy-people-outside-smile-sun-nature-eduardo-dutra-620857-unsplash.jpg')
img = cv2.imread(input('Enter filename of photo : '))
resize = tf.image.resize(img, (256,256))
print ('1313')
print(img)
new_model = load_model('models/imageclassifier.h5')
emotion_prediction = new_model.predict(np.expand_dims(resize/255, 0))
if emotion_prediction > 0.5:
print(f'Predicted classification is Sad')
print(emotion_prediction)
plt.imshow(img)
plt.suptitle('This person is Sad 😢' )
plt.show()
else:
print(f'Predicted classification is Happy')
print(emotion_prediction)
plt.imshow(img)
plt.suptitle('This person is Happy 😁' )
plt.show()
main()