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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KI-gestütztes Marketing
Backend Development
Mood Meter
Commits
f3ff164b
Commit
f3ff164b
authored
1 year ago
by
Simon Flaisch
Browse files
Options
Downloads
Patches
Plain Diff
Switched to fastapi, made some overall improvements and prepared the code for the latency-tests
parent
e933887f
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Consumer.py
+1
-1
1 addition, 1 deletion
Consumer.py
ReceiveVideostreaming.py
+20
-0
20 additions, 0 deletions
ReceiveVideostreaming.py
Test.html
+1
-1
1 addition, 1 deletion
Test.html
main.py
+30
-32
30 additions, 32 deletions
main.py
with
52 additions
and
34 deletions
Consumer.py
+
1
−
1
View file @
f3ff164b
...
@@ -4,7 +4,7 @@ import paho.mqtt.client as mqtt
...
@@ -4,7 +4,7 @@ import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
# The callback for when the client receives a CONNACK response from the server.
def
on_connect
(
client
,
userdata
,
flags
,
reason_code
,
properties
):
def
on_connect
(
client
,
userdata
,
flags
,
reason_code
,
properties
):
print
(
f
"
Connected with result code
{
reason_code
}
"
)
print
(
f
"
Connected with result code
{
reason_code
}
"
)
client
.
subscribe
(
"
Topic1
"
)
client
.
subscribe
(
"
Finger
"
)
# The callback for when a PUBLISH message is received from the server.
# The callback for when a PUBLISH message is received from the server.
def
on_message
(
client
,
userdata
,
msg
):
def
on_message
(
client
,
userdata
,
msg
):
...
...
This diff is collapsed.
Click to expand it.
ReceiveVideostreaming.py
0 → 100644
+
20
−
0
View file @
f3ff164b
import
cv2
from
imutils.video
import
VideoStream
cv2
.
namedWindow
(
"
preview
"
)
vc
=
VideoStream
(
"
http://localhost:88/video_feed
"
).
start
()
while
True
:
frame
=
vc
.
read
()
cv2
.
imshow
(
"
preview
"
,
frame
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'
q
'
):
break
cv2
.
destroyWindow
(
"
preview
"
)
vc
.
release
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Test.html
+
1
−
1
View file @
f3ff164b
...
@@ -4,6 +4,6 @@
...
@@ -4,6 +4,6 @@
</head>
</head>
<body>
<body>
<h1>
HHZ Livestream
</h1>
<h1>
HHZ Livestream
</h1>
<img
src=
"http://localhost:8
8
/video_feed"
>
<img
src=
"http://localhost:8
9
/video_feed"
>
</body>
</body>
</html>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
30
−
32
View file @
f3ff164b
import
os
import
cv2
import
cv2
import
uvicorn
import
warnings
import
warnings
import
numpy
as
np
import
numpy
as
np
import
pyttsx3
import
pyttsx3
...
@@ -11,11 +11,8 @@ import json
...
@@ -11,11 +11,8 @@ import json
import
requests
import
requests
from
PIL
import
Image
from
PIL
import
Image
from
imutils.video
import
VideoStream
from
imutils.video
import
VideoStream
from
flask
import
Response
from
fastapi
import
FastAPI
from
flask
import
Flask
from
fastapi.responses
import
StreamingResponse
from
flask
import
render_template
import
argparse
import
datetime
import
imutils
import
imutils
...
@@ -29,19 +26,38 @@ engine = pyttsx3.init('sapi5')
...
@@ -29,19 +26,38 @@ engine = pyttsx3.init('sapi5')
app
=
Flask
(
__name__
)
app
=
FastAPI
()
# Definiere Kamera und starte Videoaufnahme
# Definiere Kamera und starte Videoaufnahme
video_capture
=
VideoStream
(
src
=
0
).
start
()
try
:
video_capture
=
VideoStream
(
"
http://localhost:80/video_feed
"
).
start
()
except
Exception
as
e
:
print
(
f
"
We couldn
'
t reach the camera
"
)
exit
()
# Definiere, welche Cascade OpenCV verwenden soll
# Definiere, welche Cascade OpenCV verwenden soll
face_cascade
=
cv2
.
CascadeClassifier
(
'
haarcascade_frontalface_default.xml
'
)
face_cascade
=
cv2
.
CascadeClassifier
(
'
haarcascade_frontalface_default.xml
'
)
time
.
sleep
(
2.0
)
time
.
sleep
(
2.0
)
class
Main
:
class
Main
:
def
__init__
(
self
):
self
.
outputFrame
=
None
self
.
lock
=
threading
.
Lock
()
self
.
wait_in_thread
=
None
self
.
streamThread
=
None
self
.
analysis_results
=
None
self
.
analysis_thread
=
None
self
.
speaking_thread
=
None
# Verfolgt den aktuellen Sprech-Thread
self
.
main_time
=
0
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
stream
(
self
):
def
stream
(
self
):
app
.
run
(
host
=
"
localhost
"
,
port
=
88
,
debug
=
True
,
uvicorn
.
run
(
host
=
"
localhost
"
,
port
=
89
,
app
=
app
)
threaded
=
True
,
use_reloader
=
False
)
def
streamingThread
(
self
):
def
streamingThread
(
self
):
self
.
streamThread
=
threading
.
Thread
(
target
=
self
.
stream
)
self
.
streamThread
=
threading
.
Thread
(
target
=
self
.
stream
)
self
.
streamThread
.
daemon
=
True
self
.
streamThread
.
daemon
=
True
...
@@ -92,21 +108,6 @@ class Main:
...
@@ -92,21 +108,6 @@ class Main:
while
len
(
self
.
unacked_publish
):
while
len
(
self
.
unacked_publish
):
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
msg
.
wait_for_publish
()
msg
.
wait_for_publish
()
def
__init__
(
self
):
self
.
outputFrame
=
None
self
.
lock
=
threading
.
Lock
()
self
.
wait_in_thread
=
None
self
.
streamThread
=
None
self
.
analysis_results
=
None
self
.
analysis_thread
=
None
self
.
speaking_thread
=
None
# Verfolgt den aktuellen Sprech-Thread
self
.
main_time
=
0
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
speak
(
self
,
text
):
def
speak
(
self
,
text
):
...
@@ -167,8 +168,6 @@ class Main:
...
@@ -167,8 +168,6 @@ class Main:
def
face_recognition
(
self
,
mqttc
):
def
face_recognition
(
self
,
mqttc
):
while
True
:
while
True
:
#cv2.namedWindow("video_capture", cv2.WINDOW_NORMAL)
#cv2.resizeWindow("video_capture", 800, 600)
frame
=
video_capture
.
read
()
frame
=
video_capture
.
read
()
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
...
@@ -231,7 +230,6 @@ class Main:
...
@@ -231,7 +230,6 @@ class Main:
frame
=
cv2
.
cvtColor
(
np
.
array
(
frame_pil
),
cv2
.
COLOR_RGB2BGR
)
frame
=
cv2
.
cvtColor
(
np
.
array
(
frame_pil
),
cv2
.
COLOR_RGB2BGR
)
if
self
.
speaking_thread
and
self
.
speaking_thread
.
is_alive
():
if
self
.
speaking_thread
and
self
.
speaking_thread
.
is_alive
():
#self.flag = False
self
.
it
=
self
.
it
+
1
self
.
it
=
self
.
it
+
1
frame_pillow
=
Image
.
fromarray
(
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
))
# Auslagern
frame_pillow
=
Image
.
fromarray
(
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
))
# Auslagern
...
@@ -273,12 +271,12 @@ if __name__ == '__main__':
...
@@ -273,12 +271,12 @@ if __name__ == '__main__':
main
=
Main
()
main
=
Main
()
main
.
welcome_message
()
main
.
welcome_message
()
main
.
streamingThread
()
main
.
streamingThread
()
@app.
route
(
"
/video_feed
"
)
@app.
get
(
"
/video_feed
"
)
def
video_feed
():
def
video_feed
():
# return the response generated along with the specific media
# return the response generated along with the specific media
# type (mime type)
# type (mime type)
return
Response
(
main
.
generate
(),
return
Streaming
Response
(
main
.
generate
(),
mime
type
=
"
multipart/x-mixed-replace; boundary=frame
"
)
media_
type
=
"
multipart/x-mixed-replace; boundary=frame
"
)
main
.
currentclient
=
main
.
connectwithmqtt
(
adress
=
"
localhost
"
,
targetport
=
1883
)
main
.
currentclient
=
main
.
connectwithmqtt
(
adress
=
"
localhost
"
,
targetport
=
1883
)
main
.
face_recognition
(
mqttc
=
main
.
currentclient
)
main
.
face_recognition
(
mqttc
=
main
.
currentclient
)
...
...
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
register
or
sign in
to comment