DynAIkonTrap.camera#

Provides a simplified interface to the PiCamera library class. The Camera class provides the Frames from the camera’s stream via a queue. Initialising the Camera takes care of setting up the necessary motion vector and image streams under the hood.

A Frame is defined for this system as having the motion vectors, as used in H.264 encoding, a JPEG encode image, and a UNIX-style timestamp when the frame was captured.

Classes

Camera(settings[, read_from])

Acts as a wrapper class to provide a simple interface to a stream of camera frames.

Frame(image, motion, timestamp)

A frame from the camera consisting of motion and image information as well as the time of capture.

ImageReader(synchroniser)

MovementAnalyser(camera, synchroniser)

PiMotionAnalysis()

Synchroniser(output)

class Camera(settings: CameraSettings, read_from: VideoStream = None)#

Acts as a wrapper class to provide a simple interface to a stream of camera frames. Each frame consists of motion vectors and a JPEG image. The frames are stored on an internal queue, ready to be read by any subsequent stage in the system.

Constructor for Camera. Can be used to instanciate a camera hardware instance from settings or frames may be fed in via the argument read_from, this allows compatbility with the Vid2Frames library.

Parameters:
  • settings (CameraSettings) – Takes a CameraSettings object to initialise and start the camera hardware.

  • read_from (VideoStream, optional) – Provides capability to spoof the camera input with an emulator. An instance of the Vid2Frames class, VideoStream may be used to read frames from a video, for example. Defaults to None.

capture_still(filename: str, fmt='image/jpeg')#

Captures a still image on the video port, can be called while the camera is recording. Insipred by picamera example: https://picamera.readthedocs.io/en/release-1.13/recipes2.html#capturing-images-whilst-recording :param filename: filename to save capture to, jpg. :type filename: str

close()#
empty() bool#

Indicates if the queue of buffered frames is empty

Returns:

True if there are no more frames, otherwise False

Return type:

bool

get() Frame#

Retrieve the next frame from the camera

Raises:

Empty – If the camera has not captured any frames since the last call

Returns:

A frame from the camera video stream

Return type:

Frame

class Frame(image: bytes, motion: ndarray, timestamp: float)#

A frame from the camera consisting of motion and image information as well as the time of capture.

image: bytes#
motion: ndarray#
timestamp: float#
class ImageReader(synchroniser)#
write(buf)#
class MovementAnalyser(camera, synchroniser)#
analyse(motion)#
class PiMotionAnalysis#
class Synchroniser(output: Queue)#
tick_image_frame(image)#
tick_movement_frame(motion)#