Package pyvision :: Package beta :: Module vtm :: Class VideoTaskManager
[hide private]
[frames] | no frames]

Class VideoTaskManager

source code

object --+
         |
        VideoTaskManager

The framework provide by this class will allow complex video processing systems to be constructed from simple tasks. Often video processing loops can be complicated because data needs to persist across many frame and many operations or tasks need to be completed to solve a video analysis problem. This class allows for many small and simple tasks to be managed in a way that can produce a complex and powerful system. #

Tasks request only the data they need, which keeps the complexity of tasks as simple as possible. This also reduces the coupling between tasks and eliminates complex video processing loops. The video task manager handles much of the complexity of the video processing system like data buffering, and insures that each task gets its required data. #

This class manages tasks that are run on video frames. The video task manager maintains a list of data objects and task objects. Each task is a listener for data objects. When the data objects are avalible required to execute a task the tasks execute method will be called and the required data items will be passed as arguments. #

New frames are added using the addFrame method. When a frame is added it creates a data item that includes a frame_id, a data type of "FRAME", and a pv.Image that contains the frame data. Tasks can register to receive that frame data or any data products of other tasks and when that data becomes available the task will be executed.

Instance Methods [hide private]
 
__init__(self, debug_level=0, buffer_size=10, show=False)
Create a task manager.
source code
 
addTaskFactory(self, task_factory, *args, **kwargs)
This function add a task factory function to the video task manager.
source code
 
addFrame(self, frame, ilog=None)
Adds a new frame to the task manager and then start processing.
source code
 
addData(self, data_list)
Add additional data for this frame.
source code
 
addDataItem(self, data_item)
Process any new data items and associate them with tasks.
source code
 
_createTasksForFrame(self, frame_id)
This calls the task factories to create tasks for the current frame.
source code
 
_runTasks(self, flush=False)
Run any tasks that have all data available.
source code
 
flush(self)
Run all tasks that can be run and then finish up.
source code
 
_evaluateTask(self, task, flush=False)
Attempts to run a task.
source code
 
_remainingTasksForFrame(self, frame_id)
Returns: the number of tasks that need to be run for this frame.
source code
 
showFrames(self, ilog=None)
Show any frames with no remaining tasks.
source code
 
recordingFile(self, filename)
Set up an output file for recording.
source code
 
playbackFile(self, filename, cache=False)
Set up an input file for playback.
source code
 
recordingFilter(self, data_types)
Only recorded data_types in the list.
source code
 
taskFilter(self, task_types)
Only generate tasks in the list.
source code
 
playbackFilter(self, data_types)
Only playback data_types in the list.
source code
 
asGraph(self, as_image=False)
This uses runtime analysis to create a dataflow graph for this VTM.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, debug_level=0, buffer_size=10, show=False)
(Constructor)

source code 

Create a task manager.

Parameters:
  • debug_level (int) - 0=quiet, 1=errors, 2=warnings, 3=info, 4=verbose
  • buffer_size (int) - the size of the frame and data buffer.
Overrides: object.__init__

addTaskFactory(self, task_factory, *args, **kwargs)

source code 

This function add a task factory function to the video task manager. The function is called once for every frame processed by the VideoTaskManager. This function should take one argument which is the frame_id of that frame. The task factory should return an instance of the VideoTask class that will perform processing on this frame. There are three options for implementing a task factory. #

  • A class object for a VideoTask which has a constructor that takes a frame_id as an argument. When called the constructor for that class and will create a task.
  • A function that takes a frame id argument. The function can create and return a task.
  • Any other object that implements the __call__ method which returns a task instance.

Any additional arguments or keyword arguments passed to this to this function will be pased after the frame_id argument to the task factory. #

Parameters:
  • task_factory (callable) - a function or callible object that returns a task.
  • profile (True | False) - Keyword argument. If true, profile data will be generated for each call to this task.

addFrame(self, frame, ilog=None)

source code 

Adds a new frame to the task manager and then start processing.

Parameters:
  • frame (pv.Image) - the next frame of video.

addData(self, data_list)

source code 

Add additional data for this frame. The data list should contain a list tuples where each tuple of (label, data)

flush(self)

source code 

Run all tasks that can be run and then finish up. The LAST_FRAME data item will be set to true for the last frame inserted.

_evaluateTask(self, task, flush=False)

source code 

Attempts to run a task. This is intended to be run within a filter operation.

Returns:
false if task should be deleted and true otherwise.

_remainingTasksForFrame(self, frame_id)

source code 
Returns:
the number of tasks that need to be run for this frame.