Sources

Sources abstract the details of implementation of different signal acquisition methods. The obtained signal is fragmented into a sequence of a meaningful units of information. Currently, only video frames are supported but the concept could be extended to audio signal buffers or other signal types.

Design guidelines for sources

Sources should contemplate a method of guaranteeing an output rate that the processing pipeline can cope with, being the most naive implementation providing an attribute to drop frames or reduce frame quality.

API reference

This module contains the core components for video input.

  • VideoReader: reads a video file and triggers an iteration of the pipeline for each frame, unless the skip_frames parameter is specified.

  • ImageSequenceReader: reads a list containing a sequence of images.

class videoanalytics.pipeline.sources.ImageSequenceReader(name, context, img_seq: list)

Reads sequence of images from a list of files.

This component WRITES the following entries in the global context:

Variable name

Description

IMG_FILENAME

Input image name.

INPUT_WIDTH

Input image width in pixels.

INPUT_HEIGHT

Input image height in pixels.

FRAME

Numpy array representing the frame.

START_FRAME

First element of the sequence (always 0, only for compatibility with other sources)

TOTAL_FRAMES

Length of the image sequence.

Parameters
  • name (str) – the component unique name.

  • context (dict) – The global context.

  • img_seq (list) – sequence of images.

get_progress()

This method is called for components that read from a source of known length.

read()

This method is called until it returns None or the processing is cancelled.

setup()

This method is called after all components from the pipeline are instanced.

shutdown()

This method is called after the process finished.

class videoanalytics.pipeline.sources.VideoReader(name, context, video_path: str, start_frame=0, max_frames=None, step_frames=1)

Reads video from a file using OpenCV capture device interface.

This component WRITES the following entries in the global context:

Variable name

Description

INPUT_FPS

Input video FPS.

INPUT_WIDTH

Input video width in pixels.

INPUT_HEIGHT

Input video height in pixels.

START_FRAME

Input video start frame.

TOTAL_FRAMES

Input video width in pixels.

STEP_FRAMES

Input video width in pixels.

FRAME

Numpy array representing the frame.

Parameters
  • name (str) – the component unique name.

  • context (dict) – The global context.

  • video_path (str) – input video filename.

  • start_frame (int) – start frame (default is 0).

  • max_frames (int) – maximum number of frames to read (default is 1).

  • step_frames (int) – default is 1, use other values to drop frames. This option is used for pipelines that can not cope with a high framerate.

get_progress()

This method is called for components that read from a source of known length.

read()

This method is called until it returns None or the processing is cancelled.

setup()

This method is called after all components from the pipeline are instanced.

shutdown()

This method is called after the process finished.