computer vision project
This commit is contained in:
commit
849476cc31
16
README.md
Normal file
16
README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Project for the subject of computer vision
|
||||
|
||||
## Task
|
||||
|
||||
The goal of the project is to create a system that recognizes emotions in real time.
|
||||
|
||||
## Start system
|
||||
|
||||
- unpack input.zip file
|
||||
- <code>python project.py</code>
|
||||
|
||||
## Learn and use model
|
||||
- go to Google Colab
|
||||
- import and run `modelTrainer.ipynb` file
|
||||
- copy `model.json` and `model_weights.h5` to `input` dir
|
||||
- run: <code>python project.py</code>
|
33314
input/haarcascade_frontalface_default.xml
Normal file
33314
input/haarcascade_frontalface_default.xml
Normal file
File diff suppressed because it is too large
Load Diff
1
input/model.json
Normal file
1
input/model.json
Normal file
File diff suppressed because one or more lines are too long
BIN
input/model_weights.h5
Normal file
BIN
input/model_weights.h5
Normal file
Binary file not shown.
1
modelTrainer.ipynb
Normal file
1
modelTrainer.ipynb
Normal file
File diff suppressed because one or more lines are too long
55
project.py
Normal file
55
project.py
Normal file
@ -0,0 +1,55 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
from tensorflow.keras.models import model_from_json
|
||||
|
||||
model_json_file = './input/model.json'
|
||||
model_weights_file = './input/model_weights.h5'
|
||||
with open(model_json_file, "r") as json_file:
|
||||
loaded_model_json = json_file.read()
|
||||
loaded_model = model_from_json(loaded_model_json)
|
||||
loaded_model.load_weights(model_weights_file)
|
||||
|
||||
face_cascade = cv2.CascadeClassifier('./input/haarcascade_frontalface_default.xml')
|
||||
img_size = 64
|
||||
cap = cv2.VideoCapture(0)
|
||||
import copy
|
||||
|
||||
while True:
|
||||
|
||||
ret, frame = cap.read()
|
||||
img = copy.deepcopy(frame)
|
||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||
for (x,y,w,h) in faces:
|
||||
fc = gray[y:y+h, x:x+w]
|
||||
|
||||
roi = cv2.resize(fc, (img_size,img_size))
|
||||
pred = loaded_model.predict(roi[np.newaxis, :, :, np.newaxis])
|
||||
text_idx=np.argmax(pred)
|
||||
text_list = ['Angry', 'Disgust', 'Fear', 'Happy', 'Neutral', 'Sad', 'Surprise']
|
||||
if text_idx == 0:
|
||||
text= text_list[0]
|
||||
if text_idx == 1:
|
||||
text= text_list[1]
|
||||
elif text_idx == 2:
|
||||
text= text_list[2]
|
||||
elif text_idx == 3:
|
||||
text= text_list[3]
|
||||
elif text_idx == 4:
|
||||
text= text_list[4]
|
||||
elif text_idx == 5:
|
||||
text= text_list[5]
|
||||
elif text_idx == 6:
|
||||
text= text_list[6]
|
||||
cv2.putText(img, text, (x, y-5),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.45, (255, 0, 255), 2)
|
||||
img = cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 2)
|
||||
|
||||
|
||||
cv2.imshow("frame", img)
|
||||
key = cv2.waitKey(1) & 0xFF
|
||||
if key== ord('q'):
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
Loading…
Reference in New Issue
Block a user