Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mood Meter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KI-gestütztes Marketing
Backend Development
Mood Meter
Commits
0d4ef4dc
Commit
0d4ef4dc
authored
Apr 11, 2024
by
Amel Abdic
Browse files
Options
Downloads
Patches
Plain Diff
Added speaking mascot
parent
85c248cb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+39
-3
39 additions, 3 deletions
main.py
with
39 additions
and
3 deletions
main.py
+
39
−
3
View file @
0d4ef4dc
...
...
@@ -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
)
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment