In this article I will guide you through how I built a Node-RED flow that will enable you to extract the inferenced results that the OpenVINO engine has created from the Vizi-AI-starter-kit profile.
I have already built this flow and it is automatically deployed as part of the Vizi-AI-starter-kit.
In this guide I will walk you through what I did to build this flow and how each component interacts with the other.
If you require access to the original flow for any reason it is located here (https://vizi-ai-ppa.s3.eu-west-2.amazonaws.com/node-red/flows.json).
If you need to you can re-deploy it to your Vizi-AI once the Node-RED application has been deployed, deployment instructions can be found here (How to import a flows file into Node-RED).
I thought taking you through the journey of how I built this flow to retrieve data from ADLINK Data River and separated the data out to which an action could be taken might be useful.
To start with if you have already deployed your vizi-ai-starter-kit profile as per the Windows or Linux deployment instructions then you simply need to navigate to “http://<YOUR-DEVICE-IP:1880″ this will take you to the user interface for Node-RED where you will your existing deployment.
Before I start explaining how I built this Node-RED flow I think its worth introducing you to a subset of the “nodes” as they are called in Node-RED.
The nodes that we are interested for this article are:
- Input: Data River – this is the node that will enable access to the Data River
- Function – switch, the switch node allows us to take the array generated by the function and split out the component parts as we wish, out putting the ones we choose
- common – debug, the debug node allows us to view and debug what is going on within Node-RED once it has been deployed and is a key tool to check the outputs are working as desired
To get started I dragged the Data River node onto my workspace, you will see once it is placed it appears with a default name of “subscribe”.
To get started double click the node.
You will be presented with a popup on the right hand side of the screen to allow you to configure the Data River subscriber node.
The information I needed to provide was:
- Name – this is the name of this Node within the Node-RED application
- ContextID – this is the context that the Node will be represented on the Data River as to connect to the Data River you must be a “Thing” on the Data River
- Description – This is a human readable description for what this “thing” is on the Data River
- Tag Group – This is the tag group that you want to extract data from within the Data River, there are several options by default available within Node-Red
- Input name – the name that you want to provide as an input – no spaces or non alphabetical characters are allowed in this input box
I have entered all the details as shown below in green and clicked Done to save the changes.
You will see that the name of the node has now changed to be the name I provided above.
Next drag on a function and double click to edit.
I firstly need to provide it with a name that will help identify the node within Node-RED.
I have given it the name of “Extract Inferenced Results” and then added my code, as you can see from the comments in my code I have:
- Extracted the detectionBoxes from the message payload data.
- Retired an array of detection box labels from the data
- Uploaded the message payload with the detection label information
Then click Done to save
// Get only the detection boxes from the message let detectionBoxes = msg.payload.data; // Get an array of object labels from the detection boxes let detectedObjects =  detectionBoxes.forEach(detectionBox => detectedObjects.push(detectionBox.obj_label) ); // Update msg.payload msg.payload = detectedObjects; return msg;
Next we need to make the connection, drag a line with between connector on Data River node to the function node, this ensures that data flows from the Data River node to where we want it.
Next drag a switch on to the workspace and double click to open.
The switch function allows us to extract the array elements of the message payload and extract only the elements that we are interested in.
To start give the switch node a name, this will be used within Node-RED to identify the node in the workspace.
Next Click on the dropdown list and select the contains element and then add the text that you are looking for within the array.
As you can see I have given the switch a name “Contents switch” and asked it to look where the message payload “contains” the label “person”.
To add more items to look for click Add at the bottom of the window, highlighted in Red.
As part of my example that I have provided I wanted to also see instances where a “car” or a “fire hydrant” were seen, once finished click Done.
Next we need to connect the function to the switch, do so by dragging a line from the function (Extract Inferenced Results) to the Switch (Contents switch).
You will also notice that the Contents switch has 3 outputs on the right hand side of the node, for explanation I have colour coded them, they will not appear colour coded in Node-RED.
The outputs shown in purple, orange and black are the 3 properties that we set previously in the Contents switch, they are presented in the order that I have added them in the Switch.
Next I dragged a function onto my workspace, this function is intended to take the output from one of the switch nodules and convert it into a meaningful message. Double click the function to start.
When adding the function a name must be provided, this name is for identifying this node within Node-RED only.
Also add the message you want to send based of the function being triggered.
As I am adding a function against the nodule that is triggered when a person appears within the Content switch, I set my message payload to include a message that is appropriate as below.
I then needed to connect the Content switch “person” out put nodule to my function to enable it to be triggered.
I then repeated the process to raise a message when Vizi see’s a car in the inference engine.
And also for a fire hydrant, you will notice all 3 items were items I selected in the contents switch, you would be able to add more items in the context switch or edit these to change the Node-RED flow to trigger from the results you expect.
Next I wanted to be able to see within Node-RED the data flowing in real time from the Vizi once the Node-RED flow is deployed. To do this I select a debug node
and I drag it on to my work space.
There is no need to configure the debug tool simply connect the output from your functions to it.
Then click deploy in the top right hand side
Sometimes you may see this message, if you do there is no need to do anything.
Once the flow is deployed you will see the deploy button become grayed out, to view the output from the debug simply click the tab that contains a picture of a Bug.
As you can see in the debug window the outputted messages from each of the functions
To utilise the power of Node-RED you can perform a multitude of tasks, the key is doing what I have done above which is provide a mechanism to extract inferenced data results from the data river and drive an action.
I actually went one stop further and implemented the Twilio connector which we have recently added to our version of Node-RED.
This enabled me to connect Twilio to my Vizi through Node-RED to out put the messages, we just saw in the debug screen above, to SMS as shown below.