Commit c4eb2a94 authored by Arne Gerdes's avatar Arne Gerdes

Neue Kommentare hinzugefügt

parent c9a3225f
from threading import Thread from threading import Thread
import cv2 import cv2
class WebcamVideoStream: class WebcamVideoStream:
def __init__(self, src=0): def __init__(self, src=0):
# initialize the video camera stream and read the first frame """
# from the stream initialisiere den Webcam Stream und liest den ersten Frame aus dem Stream
"""
self.stream = cv2.VideoCapture(src) self.stream = cv2.VideoCapture(src)
(self.grabbed, self.frame) = self.stream.read() (self.grabbed, self.frame) = self.stream.read()
# initialize the variable used to indicate if the thread should """
# be stopped Initialisiere die Variable, die angibt, ob der Thread gestoppt werden soll
"""
self.stopped = False self.stopped = False
def start(self): def start(self):
# start the thread to read frames from the video stream """
starte den Thread, um Frames aus dem Webcam Stream zu lesen
"""
Thread(target=self.update, args=()).start() Thread(target=self.update, args=()).start()
return self return self
def update(self): def update(self):
# keep looping infinitely until the thread is stopped """
Endloss Schleife, bis der Thread gestoppt wird
"""
while True: while True:
# if the thread indicator variable is set, stop the thread """
Wenn die Thread-Indikator-Variable gesetzt ist, stoppt diese den Thread
"""
if self.stopped: if self.stopped:
return return
# otherwise, read the next frame from the stream """
Ansonsten wird der nächste Frame aus dem Stream gelesen
"""
(self.grabbed, self.frame) = self.stream.read() (self.grabbed, self.frame) = self.stream.read()
def read(self): def read(self):
# return the frame most recently read """
gibt den zuletzt gelesenen Frame zurück
"""
return self.frame return self.frame
def stop(self): def stop(self):
# indicate that the thread should be stopped """
gibt an, dass der Thread gestoppt werden soll
"""
self.stopped = True self.stopped = True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment