In this tutorial we take our Pi-Zero security camera scenario one step further and add image recognition supplied by the very cool AWS Rekognition service using the FRED Node-RED cloud service.
The UI for the application is shown below. We have a button that requests a new photo from the remote camera. Once the photo is received, the image is processed and the recognition service labels are shown underneath.
To build this application, we’ll use two new flows hosted in the cloud. The first flow will trigger and receive security camera images from a remote location as described in a previous tutorial (tutorial link). We’ll modify this flow slightly so that when we receive an image from a remote location, we’ll also store the image in S3 to trigger image processing in AWS.
To do the image processing, we’ll set up a lambda function for processing images in an S3 bucket. This function will call AWS Rekognition for performing image recognition and labelling of the image. To return the labels back to Node-RED running in the FRED service, we’ll use AWS SQS. To do this, we will make use of these AWS services using the node-red-aws-contrib node.
The first remote security dashboard flow is shown below.
In this flow we use a dashboard ui button node called ‘Take a picture’ to trigger a message which is sent to a remote flow running on a Raspberry Pi via MQTT to take a photo as described in a previous tutorial. The Pi’s camera flow POSTs the image it takes to the /api/camera http endpoint shown.
We then move the image data in the http body to the message payload and stringify it for the template node to display it using the function node.
The image payload is current base64 encoded. Before saving the image in S3, we decode it using the base64 node. We then use the S3 node from node-red-contrib-aws to save the image in a bucket.
Once the image is in S3, we let the AWS systems do their thing. To do so, we need to set up an AWS lambda function to call the Rekognition service and return our results. We’ll need to set up an SQS queue to receive results from the image recognition service.
Rekognition APIs to detect faces, labels and index faces in S3 Object.
We’ve added an SQS delete node to clean up messages from the queue once processed, and a catch node to view any errors that are thrown.
That does it. Now, when we click on the Take a Picture button in our dashboard, we send a signal off to our remote Pi Zero to take a photo. The photo is pushed into the cloud for display and image analysis on our Node-RED Dashboard.
To keep things brief, some of the details may have been glossed over in this tutorial, and of course there are many ways to extend it. If you have any questions about this tutorial, want to get a copy of the JSON flows, or find any errors, feel free to contact us by email.
About Sense Tecnic: Sense Tecnic Systems Inc have been building IoT applications and services since 2010. We provide FRED, cloud hosted Node-RED as a service to the community. We also offer a commercial version to our customers, as well as professional services. Learn more.