Skip to content

Commit

Permalink
small changes for running statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterwolfert committed Jul 26, 2018
1 parent e1b9724 commit fe09c11
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions script/smiling_detection_improved.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import numpy as np
import cv2
import os
import time
from face_recognition import face_locations
import keras
from keras.models import model_from_json
from skimage.measure import block_reduce
from skimage.transform import resize

def liveCam(model):
video = cv2.VideoCapture('/dev/video0')
while True:
def liveCam(model, video):
video = cv2.VideoCapture(video)
smile = 0.0
frames = video.get(cv2.CAP_PROP_FRAME_COUNT)
for i in range(int(video.get(cv2.CAP_PROP_FRAME_COUNT))):
# Capture frame-by-frame
#time.sleep(1)
ret, frame = video.read()
Expand All @@ -25,9 +28,9 @@ def liveCam(model):
head = head.astype(np.float)
head = np.array([[head]])
head = np.transpose(head, [0, 2, 3, 1])
print("Working")
probabilities = model.predict(head)[0]
print("Results: {}".format(probabilities))
if probabilities[1] > smile:
smile = probabilities[1]
# Display the resulting frame
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imshow('Video', frame)
Expand All @@ -36,10 +39,23 @@ def liveCam(model):
# When everything is done, release the capture
video.release()
cv2.destroyAllWindows()
return smile

def main():
model = model_from_json(open('models/model_smiling.json').read())
model.load_weights('models/weights_smiling.h5')
for filename in os.listdir('data/l2torclips/small'):
if filename.endswith(".mp4"):
print(filename)
try:
smile_pred = liveCam(model,'data/l2torclips/small/' + filename)
print(smile_pred)
stat = "{}, {}\n".format(filename, smile_pred)
with open("smiling.txt", "a") as gz:
gz.write(stat)
except ValueError as err:
continue

liveCam(model)

if __name__ == '__main__':
Expand Down

0 comments on commit fe09c11

Please sign in to comment.