Node¶
- class mmpose.apis.webcam.nodes.Node(name: str, enable_key: Optional[Union[str, int]] = None, max_fps: int = 30, input_check_interval: float = 0.01, enable: bool = True, daemon: bool = False, multi_input: bool = False)[source]¶
Base class for node, which is the interface of basic function module.
Node
inheritsthreading.Thread
. All subclasses should override following methods:process()
bypass()
(optional)
- Parameters
name (str) – The node name (also thread name)
enable_key (str|int, optional) – Set a hot-key to toggle enable/disable of the node. If an int value is given, it will be treated as an ascii code of a key. Please note: (1) If
enable_key
is set, thebypass()
method need to be overridden to define the node behavior when disabled; (2) Some hot-keys are reserved for particular use. For example: ‘q’, ‘Q’ and 27 are used for exiting. Default:None
max_fps (int) – Maximum FPS of the node. This is to avoid the node running unrestrictedly and causing large resource consuming. Default: 30
input_check_interval (float) – Minimum interval (in millisecond) between checking if input is ready. Default: 0.001
enable (bool) – Default enable/disable status. Default:
True
daemon (bool) – Whether node is a daemon. Default:
True
multi_input (bool) – Whether load all messages in buffer. If False, only one message will be loaded each time. Default:
False
- bypass(input_msgs: Dict[str, mmpose.apis.webcam.utils.message.Message]) → Optional[mmpose.apis.webcam.utils.message.Message][source]¶
The method that defines the node behavior when disabled.
Note that a node must override this method if it has enable_key. This method has the same signature as
process()
.- Parameters
input_msgs (dict[str,
Message
]) – The input data collected from the buffers. For each item, the key is the input_name of the registered input buffer, and the value is a Message instance fetched from the buffer (or None if the buffer is non-trigger and not ready).- Returns
The output message of the node which will be send to all registered output buffers.
- Return type
- on_exit()[source]¶
This method will be invoked on event _exit_.
Subclasses should override this method to specifying the exiting behavior.
- abstract process(input_msgs: Dict[str, mmpose.apis.webcam.utils.message.Message]) → Optional[mmpose.apis.webcam.utils.message.Message][source]¶
The method that implements the function of the node.
This method will be invoked when the node is enabled and the input data is ready. All subclasses of Node should override this method.
- Parameters
input_msgs (dict[str,
Message
]) – The input data collected from the buffers. For each item, the key is the input_name of the registered input buffer, and the value is a Message instance fetched from the buffer (or None if the buffer is non-trigger and not ready).- Returns
The output message of the node which will be send to all registered output buffers.
- Return type
- register_event(event_name: str, is_keyboard: bool = False, handler_func: Optional[Callable] = None)[source]¶
Register an event. All events used in the node need to be registered in __init__(). If a callable handler is given, a thread will be create to listen and handle the event when the node starts.
- Parameters
Args –
event_name (str|int) – The event name. If is_keyboard==True, event_name should be a str (as char) or an int (as ascii)
is_keyboard (bool) – Indicate whether it is an keyboard event. If True, the argument event_name will be regarded as a key indicator.
handler_func (callable, optional) – The event handler function, which should be a collable object with no arguments or return values. Default:
None
.
- register_input_buffer(buffer_name: str, input_name: str, trigger: bool = False)[source]¶
Register an input buffer, so that Node can automatically check if data is ready, fetch data from the buffers and format the inputs to feed into process method.
The subclass of Node should invoke register_input_buffer in its __init__ method. This method can be invoked multiple times to register multiple input buffers.
- Parameters
buffer_name (str) – The name of the buffer
input_name (str) – The name of the fetched message from the corresponding buffer
trigger (bool) – An trigger input means the node will wait until the input is ready before processing. Otherwise, an inessential input will not block the processing, instead a None will be fetched if the buffer is not ready.
- register_output_buffer(buffer_name: Union[str, List[str]])[source]¶
Register one or multiple output buffers, so that the Node can automatically send the output of the process method to these buffers.
The subclass of Node should invoke register_output_buffer in its __init__ method.
- Parameters
buffer_name (str|list) – The name(s) of the output buffer(s).