示例#1
0
def infer():

    #Load model
    network = EmotionRecognition()
    network.build_network()

    #Predict
    result = network.predict(format_image_norm(image))
    label = np.argmax(result[0])
    print("Emotion: " + str(EMOTIONS[np.argmax(result[0])]))
    return label
    image = image[face[1]:(face[1] + face[2]), face[0]:(face[0] + face[3])]
    # Resize image to network size
    try:
        image = cv2.resize(image, (SIZE_FACE, SIZE_FACE),
                           interpolation=cv2.INTER_CUBIC) / 255.
    except Exception:
        print("[+] Problem during resize")
        return None
    # cv2.imshow("Lol", image)
    # cv2.waitKey(0)
    return image


# Load Model
network = EmotionRecognition()
network.build_network()

video_capture = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX

feelings_faces = []
for index, emotion in enumerate(EMOTIONS):
    feelings_faces.append(cv2.imread('./emojis/' + emotion + '.png', -1))

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

    # Predict result with network
    result = network.predict(format_image(frame))
  # Chop image to face
  face = max_area_face
  image = image[face[1]:(face[1] + face[2]), face[0]:(face[0] + face[3])]
  # Resize image to network size
  try:
    image = cv2.resize(image, (SIZE_FACE, SIZE_FACE), interpolation = cv2.INTER_CUBIC) / 255.
  except Exception:
    print("[+] Problem during resize")
    return None
  # cv2.imshow("Lol", image)
  # cv2.waitKey(0)
  return image

# Load Model
network = EmotionRecognition()
network.build_network()

video_capture = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX

feelings_faces = []
for index, emotion in enumerate(EMOTIONS):
  feelings_faces.append(cv2.imread('./emojis/' + emotion + '.png', -1))

while True:
  # Capture frame-by-frame
  ret, frame = video_capture.read()

  # Predict result with network
  result = network.predict(format_image(frame))
示例#4
0
            camera_view = Image.fromarray(camera_view)
            camera_view = ImageTk.PhotoImage(image=camera_view)
            self.camera_view_canvas.create_image(camera_view.width() / 2 + 100,
                                                 camera_view.height() / 2,
                                                 image=camera_view)
            self.update_idletasks()
            self.update()
        # When everything is done, release the capture
        video_capture.release()
        cv2.destroyAllWindows()


if __name__ == '__main__':
    # Load Model
    network = EmotionRecognition()
    network.build_network()  # build AlexNet, a kind of CNN

    musicplayer = musicPlayer.musicPlayer()
    camera_lock = threading.Lock()

    font = cv2.FONT_HERSHEY_SIMPLEX
    #load the emotion icon

    feelings_faces = []
    for index, emotion in enumerate(EMOTIONS):
        feelings_faces.append(cv2.imread('./emojis/' + emotion + '.png', -1))

    obj = SmartBudy()
    obj.mainloop()

    #GUI part
示例#5
0
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import numpy as np

from constants import *
from emotion_recognition import EmotionRecognition
from dataset_loader import DatasetLoader

# Load Model
network = EmotionRecognition()
network.build_network(loadModel=True)

data = DatasetLoader()
data.load_from_save(data_source='fer2013')

images = data.images_test
labels = data.labels_test

print('[+] Loading Data')
data = np.zeros((len(EMOTIONS), len(EMOTIONS)))

for i in range(images.shape[0]):
    if i % 1000 == 0:
        print("Progress: {}/{} {:.2f}%".format(i, images.shape[0],
                                               i * 100.0 / images.shape[0]))
    result = network.predict(images[i])
    data[np.argmax(labels[i]), np.argmax(result[0])] += 1

print("Accuracy: %f" % (np.sum(data.diagonal()) / np.sum(data)))
# Take % by column