Skip to content

basic_bot.commons.base_camera

This was originally pilfered from https://github.com/adeept/Adeept_RaspTank/blob/a6c45e8cc7df620ad8977845eda2b839647d5a83/server/base_camera.py

Which looks like it was in turn pilfered from https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited

Thank you, @adeept and @miguelgrinberg!

CameraEvent Objects

class CameraEvent(object)

An Event-like class that signals all active clients when a new frame is available.

wait

def wait() -> bool

Invoked from each client's thread to wait for the next frame.

set

def set() -> None

Invoked by the camera thread when a new frame is available.

clear

def clear() -> None

Invoked from each client's thread after a frame was processed.

BaseCamera Objects

class BaseCamera(object)

BaseCamera is an abstract base class that for camera implementations. It creates a background thread that reads frames from the camera and signals when a new frame is available.

__init__

def __init__() -> None

Start the background camera thread if it isn't running yet.

get_frame

def get_frame() -> Optional[Union[bytes, np.ndarray]]

Return the current camera frame.

frames

@staticmethod
def frames() -> Generator[Union[bytes, np.ndarray], None, None]

"Generator that returns frames from the camera.

stats

@classmethod
def stats(cls) -> dict[str, float]

Return the fps stats dictionary.