Skip to content
Snippets Groups Projects
Commit a7d65a93 authored by Simon Flaisch's avatar Simon Flaisch
Browse files

Haven't fixed the issue with the error messages but I build a html and...

Haven't fixed the issue with the error messages but I build a html and javascript files which can utilize the results of our analysis. Now we have almost the full architecture prototyped.
parent cb97c6c6
No related branches found
No related tags found
No related merge requests found
<html>
<head>
<style>
</style>
</head>
<body>
<div id="smileyContainer">No emotion recognized so far</div>
</body>
<script>
const webSocket = new WebSocket('ws://localhost:443/');
webSocket.onmessage = (event) => {
let obj = JSON.parse(event.data);
if (obj.emotion === "happy") {
smileyContainer.innerHTML = ":-)";
}
if (obj.emotion === "neutral") {
smileyContainer.innerHTML = ":-|";
}
if (obj.emotion === "angry") {
smileyContainer.innerHTML = ":-(";
}
};
</script>
</html>
\ No newline at end of file
...@@ -7,6 +7,7 @@ from deepface import DeepFace ...@@ -7,6 +7,7 @@ from deepface import DeepFace
import threading import threading
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import json import json
import os
# Initialisiere Text-to-Speech # Initialisiere Text-to-Speech
engine = pyttsx3.init('sapi5') engine = pyttsx3.init('sapi5')
...@@ -16,8 +17,6 @@ video_capture = cv2.VideoCapture(0) ...@@ -16,8 +17,6 @@ video_capture = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
class Main: class Main:
currentclient = None
unacked_publish = set()
def on_connect(self,client, userdata, flags, reason_code, properties): def on_connect(self,client, userdata, flags, reason_code, properties):
print(f"Connected with result code {reason_code}\n") print(f"Connected with result code {reason_code}\n")
client.subscribe("Topic1") client.subscribe("Topic1")
...@@ -48,20 +47,21 @@ class Main: ...@@ -48,20 +47,21 @@ class Main:
self.analysis_results = None self.analysis_results = None
self.analysis_thread = None self.analysis_thread = None
self.speaking_thread = None # Verfolgt den aktuellen Sprech-Thread self.speaking_thread = None # Verfolgt den aktuellen Sprech-Thread
self.last_speak_time = 0 # Speichert den Zeitpunkt der letzten Sprachausgabe
self.main_time = 0 self.main_time = 0
self.currentclient = None
self.unacked_publish = set()
def speak(self, text): def speak(self, text):
engine.say(text) engine.say(text)
engine.runAndWait() engine.runAndWait()
def speak_in_thread(self, text): def speak_in_thread(self, text):
current_time = time.time()
if (self.speaking_thread is None or not self.speaking_thread.is_alive()) and (current_time - self.last_speak_time > 8): if (self.speaking_thread is None or not self.speaking_thread.is_alive()):
self.last_speak_time = current_time # Aktualisiere den Zeitpunkt der letzten Sprachausgabe
self.speaking_thread = threading.Thread(target=self.speak, args=(text,)) self.speaking_thread = threading.Thread(target=self.speak, args=(text,))
self.speaking_thread.daemon = True self.speaking_thread.daemon = True
self.speaking_thread.start() self.speaking_thread.start()
def facial_analysis_thread(self, faceframe): def facial_analysis_thread(self, faceframe):
if (self.analysis_thread is None or not self.analysis_thread.is_alive()): if (self.analysis_thread is None or not self.analysis_thread.is_alive()):
self.analysis_thread = threading.Thread(target=self.facial_analysis, args=(faceframe,)) self.analysis_thread = threading.Thread(target=self.facial_analysis, args=(faceframe,))
...@@ -76,7 +76,6 @@ class Main: ...@@ -76,7 +76,6 @@ class Main:
self.speak_in_thread('Welcome to the face recognition and prediction tool of the herman hollerith center') self.speak_in_thread('Welcome to the face recognition and prediction tool of the herman hollerith center')
def face_recognition(self, mqttc): def face_recognition(self, mqttc):
last_analysis_time = time.time()
while True: while True:
ret, frame = video_capture.read() ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
...@@ -90,7 +89,6 @@ class Main: ...@@ -90,7 +89,6 @@ class Main:
analysis_results_dict = {"age": analyze.get("age", "N/A"), "gender": analyze.get("dominant_gender", "N/A"), "emotion": analyze.get("dominant_emotion", "N/A")} analysis_results_dict = {"age": analyze.get("age", "N/A"), "gender": analyze.get("dominant_gender", "N/A"), "emotion": analyze.get("dominant_emotion", "N/A")}
self.sendMessage(mqttc=mqttc, topic="Topic1", message=json.dumps(analysis_results_dict)) self.sendMessage(mqttc=mqttc, topic="Topic1", message=json.dumps(analysis_results_dict))
except Exception as e: except Exception as e:
print("Error in DeepFace Analysis:", e) print("Error in DeepFace Analysis:", e)
analyze = None analyze = None
......
const mqtt = require("mqtt");
const ws = require ("ws");
let socketserver = new ws.WebSocketServer({
port: 443
});
let client = mqtt.connect("mqtt://localhost:1883",{
username: "standardUser",
password: "GreatHHZ4Ever!"
});
client.on("connect", function() {
let topicID = "Topic1";
client.subscribe(topicID);
});
socketserver.on('connection', ws => {
console.log("new client connected");
});
socketserver.on('close', () => console.log('Client has disconnected!'));
client.on("message", function(topic, message){
socketserver.clients.forEach(client => {
client.send(message.toString());
})});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment