Processing Node
A processing node converts the data inside a data frame to an output position of its data object(s).
Frame processing node
With the normal processing node you can process a data frame. By overriding the process()
function you can
manipulate any data frame pushed to the node.
ts
import {ProcessingNode ,DataFrame ,PushOptions } from '@openhps/core';export classMyProcessingNode <In extendsDataFrame ,Out extendsDataFrame > extendsProcessingNode <In ,Out > {process (frame :In ,options ?:PushOptions ):Promise <Out > {return newPromise ((resolve ,reject ) => {resolve (frame as unknown asOut );});}}
Object processing node
In some cases you are interested in manipulating objects inside a data frame, rather than the complete data frame itself. An ObjectProcessingNode
extends a ProcessingNode
with a processObject()
function that is called for every object inside a data frame.
ts
import {ObjectProcessingNode ,DataFrame ,DataObject ,PushOptions } from '@openhps/core';export classMyObjectProcessingNode <InOut extendsDataFrame > extendsObjectProcessingNode <InOut > {processObject (object :DataObject ,frame ?:InOut ,options ?:PushOptions ):Promise <DataObject > {return newPromise ((resolve ,reject ) => {resolve (object );});}}
Multiple inlets
In the previous examples we assumed that only one type of data frame was provided to the processing node. Processing data from multiple inlets is possible. An example could be a processing node that requires both IMU and Video data to process information. Depending on the relation between the data frames, different implementations are possible.
Conditional processing
With conditional processing we have a processing node that is capable of processing different types or data from different nodes.
Example of conditional processing on frame type
ts
import {ProcessingNode ,DataFrame ,PushOptions } from '@openhps/core';import {VideoFrame ,DepthVideoFrame } from '@openhps/video';export classMyProcessingNode <In extendsDataFrame ,Out extendsDataFrame > extendsProcessingNode <In ,Out > {process (frame :In ,options ?:PushOptions ):Promise <Out > {return newPromise ((resolve ,reject ) => {if (frame instanceofVideoFrame ) {// Video data frame processing} else if (frame instanceofDepthVideoFrame ) {// Depth video data frame processing}resolve (frame as unknown asOut );});}}
Example of conditional processing on inlet node
ts
import {ProcessingNode ,DataFrame ,PushOptions } from '@openhps/core';export classMyProcessingNode <In extendsDataFrame ,Out extendsDataFrame > extendsProcessingNode <In ,Out > {process (frame :In ,options ?:PushOptions ):Promise <Out > {return newPromise ((resolve ,reject ) => {constlastNode = this.model .findNodeByUID (options .lastNode );if (lastNode .name === "A") {// Process if last node is "A"} else if (lastNode .name === "B") {// Process if last node is "B"}resolve (frame as unknown asOut );});}}