Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frank Tjado Ihmels
medienverarbeitung17.projectmood
Commits
46440f50
Commit
46440f50
authored
Dec 13, 2017
by
tihmels
Browse files
Video Input Processing in Thread ausgelagert
parent
ec6fc745
Changes
2
Hide whitespace changes
Inline
Side-by-side
projectmood/WebcamVideoStream.py
0 → 100644
View file @
46440f50
from
threading
import
Thread
import
cv2
class
WebcamVideoStream
:
def
__init__
(
self
,
src
=
0
):
# initialize the video camera stream and read the first frame
# from the stream
self
.
stream
=
cv2
.
VideoCapture
(
src
)
(
self
.
grabbed
,
self
.
frame
)
=
self
.
stream
.
read
()
# initialize the variable used to indicate if the thread should
# be stopped
self
.
stopped
=
False
def
start
(
self
):
# start the thread to read frames from the video stream
Thread
(
target
=
self
.
update
,
args
=
()).
start
()
return
self
def
update
(
self
):
# keep looping infinitely until the thread is stopped
while
True
:
# if the thread indicator variable is set, stop the thread
if
self
.
stopped
:
return
# otherwise, read the next frame from the stream
(
self
.
grabbed
,
self
.
frame
)
=
self
.
stream
.
read
()
def
read
(
self
):
# return the frame most recently read
return
self
.
frame
def
stop
(
self
):
# indicate that the thread should be stopped
self
.
stopped
=
True
\ No newline at end of file
projectmood/webcam.py
View file @
46440f50
...
...
@@ -8,7 +8,7 @@ from cv2 import WINDOW_NORMAL
import
cv2
from
WebcamVideoStream
import
WebcamVideoStream
from
face_detect
import
find_faces
from
image_commons
import
nparray_as_image
,
draw_with_alpha
...
...
@@ -36,26 +36,23 @@ def show_webcam_and_run(model, emoticons, window_size=(800, 800), window_name='M
width
,
height
=
window_size
cv2
.
resizeWindow
(
window_name
,
width
,
height
)
vc
=
cv2
.
VideoCapture
(
0
)
if
vc
.
isOpened
():
read_value
,
webcam_image
=
vc
.
read
()
else
:
print
(
"Webcam nicht gefunden"
)
return
vc
=
WebcamVideoStream
(
src
=
0
).
start
()
frame
=
vc
.
read
()
while
r
ead_val
ue
:
for
normalized_face
,
(
x
,
y
,
w
,
h
)
in
find_faces
(
webcam_imag
e
):
while
T
rue
:
for
normalized_face
,
(
x
,
y
,
w
,
h
)
in
find_faces
(
fram
e
):
prediction
=
model
.
predict
(
normalized_face
)
# do prediction
image_to_draw
=
emoticons
[(
prediction
[
0
])]
if
x
-
150
>
0
and
y
-
50
>
0
and
w
-
150
>
0
and
h
-
150
>
0
:
draw_with_alpha
(
webcam_imag
e
,
image_to_draw
,
(
x
-
150
,
y
-
50
,
w
-
150
,
h
-
150
))
draw_with_alpha
(
fram
e
,
image_to_draw
,
(
x
-
150
,
y
-
50
,
w
-
150
,
h
-
150
))
cv2
.
imshow
(
window_name
,
webcam_imag
e
)
read_value
,
webcam_imag
e
=
vc
.
read
()
cv2
.
imshow
(
window_name
,
fram
e
)
fram
e
=
vc
.
read
()
key
=
cv2
.
waitKey
(
update_time
)
if
key
==
27
:
# exit on ESC
vc
.
stop
()
break
cv2
.
destroyWindow
(
window_name
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment