95
"""Invoked from each client's thread after a frame was processed."""
self.events[get_ident()][0].clear()
class
BaseCamera(object):
thread =
None
# background thread that reads frames from camera
frame =
None
# current frame is stored here by background thread
last_access =
0
# time of last client access to the camera
event = CameraEvent()
def
__init__(self):
"""Start the background camera thread if it isn't running yet."""
if
BaseCamera.thread
BaseCamera.last_access = time.time()
# start background frame thread
BaseCamera.thread = threading.Thread(target=self._thread)
BaseCamera.thread.start()
# wait until frames are available
while
self.get_frame()
time.sleep(0)
def
get_frame(self):
"""Return the current camera frame."""
BaseCamera.last_access = time.time()
# wait for a signal from the camera thread
BaseCamera.event.wait()
BaseCamera.event.clear()
return BaseCamera.frame
@staticmethod
def
frames():
""""Generator that returns frames from the camera."""
raise
RuntimeError('Must be implemented by subclasses.')
@classmethod
def
_thread(cls):
"""Camera background thread."""
print('Starting camera thread.')
frames_iterator = cls.frames()
is
None:
is
None:
Need help?
Do you have a question about the AWR Adeept Wheeled Robot and is the answer not in the manual?