Skip to content
Snippets Groups Projects
Commit 0d4ef4dc authored by Amel Abdic's avatar Amel Abdic :8ball:
Browse files

Added speaking mascot

parent 85c248cb
Branches
No related tags found
No related merge requests found
......@@ -58,9 +58,18 @@ class Main:
self.last_chat_time = 0 # Zeitpunkt des letzten Sprechens API kosten beachten
self.currentclient = None
self.unacked_publish = set()
self.flag = False
self.selection = 3
self.it = 0
def wait(self):
self.flag = True
def wait_in_thread(self):
if self.wait_in_thread is None or not self.wait_in_thread.is_alive():
self.wait_in_thread = threading.Thread(target=self.wait)
self.wait_in_thread.daemon = True
self.wait_in_thread.start()
def speak(self, text):
engine.say(text)
......@@ -119,7 +128,7 @@ class Main:
def face_recognition(self, mqttc):
while True:
self.wait()
cv2.namedWindow("video_capture", cv2.WINDOW_NORMAL)
cv2.resizeWindow("video_capture", 800, 600)
......@@ -146,7 +155,11 @@ class Main:
if emotion in ["happy", "neutral", "sad", "fear", "suprise", "angry"]:
self.send_emotion_to_chatgpt_and_speak(emotion)
maskottchen_images = {
"mas1": cv2.imread("emoji_folder/mas1.png", cv2.IMREAD_UNCHANGED),
"mas2": cv2.imread("emoji_folder/mas2.png", cv2.IMREAD_UNCHANGED),
"mas3": cv2.imread("emoji_folder/mas3.png", cv2.IMREAD_UNCHANGED),
}
emoji_images = {
"happy": cv2.imread("emoji_folder/happy.png", cv2.IMREAD_UNCHANGED),
......@@ -179,7 +192,30 @@ class Main:
frame = cv2.cvtColor(np.array(frame_pil), cv2.COLOR_RGB2BGR)
if self.speaking_thread and self.speaking_thread.is_alive() and self.flag == True:
self.flag = False
self.it = self.it + 1
frame_pillow = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))# Auslagern
mas_pil = Image.fromarray(cv2.cvtColor(maskottchen_images["mas1"], cv2.COLOR_BGRA2RGBA))# Auslagern
mas_pil2 = Image.fromarray(cv2.cvtColor(maskottchen_images["mas2"], cv2.COLOR_BGRA2RGBA))# Auslagern
mas_pil3 = Image.fromarray(cv2.cvtColor(maskottchen_images["mas3"], cv2.COLOR_BGRA2RGBA))# Auslagern
mas_resized = mas_pil.resize((200, 200))
mas_resized2 = mas_pil2.resize((200, 200))
mas_resized3 = mas_pil3.resize((200, 200))
x_offset = 480
y_offset = 300
if self.it % self.selection == 0:
frame_pillow.paste(mas_resized, (x_offset, y_offset), mask=mas_resized)
if self.it % self.selection == 1:
frame_pillow.paste(mas_resized2, (x_offset, y_offset), mask=mas_resized)
if self.it % self.selection == 2:
frame_pillow.paste(mas_resized3, (x_offset, y_offset), mask=mas_resized)
frame = cv2.cvtColor(np.array(frame_pillow), cv2.COLOR_RGB2BGR)
cv2.imshow("video_capture", frame)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment