Source code for cvkit.pose_estimation.processors.processor_interface
from abc import ABC, abstractmethod
from cvkit.pose_estimation.data_readers import DataStoreInterface
[docs]class ProcessorMetaData:
"""
Metadata class for describing the parameters of the processor. This class will be used to generate a user interface for the processor.
INT, FLOAT, and Text uses text-field. BOOLEAN generates a checkbox. FIXED_RANGE generates a spin-box. NUMPY_ARRAY and DATA_STORE generates a button for file picker.
BODY_PART generates a drop-down to select defined body part. GLOBAL_CONFIG does not generate any UI. It is an indication to pass on the global software config to the
processor.
:param display_name: This text will be used by the ui generator for label.
:param param_type: One of the predefined static constants defined in this class
:param default: default value
:param min_val: minimum value for INT/FLOAT, minimum length for TEXT and minimum number of elements required for multiple inputs.
example: For BODY_PART, setting min_val>1 indicates that the field expects at least one body part.
:param max_val: maximum value for INT/FLOAT, maximum length for TEXT and maximum number of elements required for multiple inputs.
example: For BODY_PART, setting max_val=n indicates that the field expects at most n body parts.
:param regex: Regular expression to validate TEXT data.
:param tooltip: This will be set as tooltip by the ui generator.
:param serialize: If true, the data will be stored to file when exported else will be replace by None
"""
INT = 0x00 #: Field expects integer data (Generates LineEdit)
FLOAT = 0x01 #: Field expects float data (Generates LineEdit)
BOOLEAN = 0x02 #: Field expects boolean data (Generates n checkboxes)
TEXT = 0x03 #: Field expects string data (Generates LineEdit)
BODY_PART = 0x04 #: Field expects one or more body parts (Generates n ComboBoxes)
GLOBAL_CONFIG = 0x05 #: Field expects :py:class:`~cvkit.pose_estimation.config.PoseEstimationConfig` (user input not required)
FIXED_RANGE = 0x06 #: Field expects Float data in fixed range. (Generates SpinBox)
NUMPY_ARRAY = 0x07 #: Field expects path to a file containing numpy data (Generates FileDialog button)
DATA_STORE = 0x08 #: Field expects dictionary containing path and flavor of datastore. (Generates FileDialog button with a ComboBox for selecting flavor)
VIEWS = 0x09 #: Field expects annotation view names (Generates CheckBoxes)
FILE_MAP = 0x10 #: Field expects a dictionary mapping views to datastores. (user input not required)
FILE_PATH = 0x11 #: Field expects a path to a file. (Generates FileDialog button)
DIR_PATH = 0x12 #: Filed expects a path to a directory (Generates FileDialog button)
def __init__(self, display_name, param_type, default=None, min_val=None, max_val=None, regex='', tooltip='',
serialize=True):
self.display_name = display_name
self.param_type = param_type
self.default = default
self.min_val = min_val
self.max_val = max_val
self.regex = regex
self.tooltip = tooltip
self.serialize = serialize
[docs]class Processor(ABC):
REQUIRES_STATS = False #: Indicates whether this processor requires data statistics generated by py:class:`.ClusterAnalysis`
PROCESSOR_NAME = "Abstract" #: Name of the processor. Used as label by the UI generator.
PROCESSOR_ID = "abstract" #: Unique Processor Identifier.
PROCESSOR_SUMMARY = "Summary" #: Processor summary.
PRINT = False
META_DATA = None #: Processor parameters' metadata. UI generator uses this information to generate a form.
DISTRIBUTED = False #: Indicates whether the processor operates at body part level or skeleton level. If true, this processor can be parallelized for each body part.
def __init__(self):
self._progress = 0
self._data_store = None
self._data_ready = False
@abstractmethod
def process(self, data_store: DataStoreInterface):
pass
def get_progress(self):
return self._progress
@abstractmethod
def get_output(self):
pass
def __eq__(self, other):
if type(other) == type(self):
for key in self.META_DATA:
if self.__getattribute__(key) != other.__getattribute__(key):
return False
return True
return False