Face Tracking and Identification Using Walle-ng

Track faces and receive notifications in real-time using a Raspberry Pi 4, Intel Neural Compute Stick, and AWS.

Project Description

This project is focused on edge computing using a Raspberry Pi, Intel Movidius Compute Stick, and a Pi-cam to detect, track, and identify faces from a video stream in real-time. The application continuously monitors and adjusts the vertical and horizontal position of two servos based on the location of faces in a frame. If a face is detected, then the activity is logged and a notification SMS will be sent to the administrator using Amazon Web Services (AWS) API Gateway, Lambda, and Simple Notification Services (SNS). This project expands on theΒ face recognition demofound in the OpenCV open model zoo.

Requirements

The total build cost less than $175 USD. The hardware can purchased from Amazon, Sparkfun, or Adafruit.

Assembly

Walle-ng can be assembled in a number of configurations, and it really depends on use case and user preference. For this install, two sections of the iUniker Raspberry Pi Cluster Case were used to house the Raspberry Pi and mount the Pan/Tilt hat. The Raspberry Pi was installed on top of the lower section of the case, and the fan was installed on the top (outside). It is recommended to install the heat sinks, connect and feed the Picam flex cable through opening in the top plastic piece, and place the female end of the GPIO ribbon cable on the Raspberry Pi GPIO pins prior to assembling the enclosure around the Raspberry Pi.

The most difficult part of assembly was attaching the pan/tilt hat to the uppermost section of the iUniker case. The top plastic enclosure piece (part that holds the pan/tilt hat) is the same piece that is used for the top of an iUniker enclosure (same as the middle piece). Once the pan/tilt hat is assembled using the provided instructions, place the hat on top of the iUniker and position it in such a way that you can mark the position of the 4 holes, located in the corners of the pan/tilt hat PCB, using a marker on the iUniker plastic. Once the holes are drilled, secure the pan/tilt hat to the plastic using the available hardware included with the iUniker kit. Notice in the image that I was only able to secure 3 out of the 4 holes to the plastic due to an opening in the iUniker plastic piece. Don't forget to attach the servo motor wiring to the bottom of the pan/tilt hat prior to securing it to the iUniker plastic.

The last part of assembly includes attaching the fan to the 5v and ground GPIO pins, plugging in the Intel Movidius Compute Stick into one of the USB3.0 ports, connecting the micro-HDMI, keyboard, and mouse (if they are intended to be used), and attaching the male end of the GPIO ribbon cable to the pan/tilt hat. The positive (red) wire of the fam should connect to GPIO2 or GPIO4, and the ground (black) wire should connect to GPIO6. A GPIO pinout for the RPI4 can be found in the references section.

Setting up Amazon Web Services

All the services used in this tutorial qualify for AWS Free Tierusage. If you do not have AWS console access, you will need to create an account on the AWS website. This section will provide details on setting up AWS SNS, API Gateway, and Lambda.

AWS Simple Notification Services (SNS)

SNS is a highly available, durable, secure, fully managed pub/sub messaging service that can be configured to send SMS or email messages to devices that subscribe to an SNS topic. For this project, one SNS topic will be created, and a mobile device will be configured as a subscriber to the topic. This is necessary to receive messages that are triggered from walle-ng events. In the AWS console, go to Simple Notification Services and perform the following actions:

Simple Notification Service (SNS) –> Topics –> Create topic

Set the following settings:

  • Name: walle-sns-topic
  • Display name: Alert
  • Click –> Create topic

Once the topic is created, a view similar to the image below should be visible. Copy down the ARN associated with the walle-sns-topic. In this example, it isΒ arn:aws:sns:us-east-1:646789677679:walle-ng-topic.

Create a subscription to the topic:

  • Click –> Create subscription
  • Topic ARN: select the walle-sns-topic (if not already selected)
  • Protocol: SMS (or email if you wish)
  • Endpoint: +15556667777 (Enter phone number, or email if email was selected)
  • Click –> Create subscription

SNS should be set up to send SMS messages to a mobile device. It is recommended to publish a test message to verify setup. In order to publish a test message, perform the following actions:

  • In the sidebar, select Topics –> walle-ng-topic
  • Click –> Publish message
  • Subject: Test
  • Message Body: Test Test
  • Click –> Publish message

AWS Lambda

AWS Lambda lets you run code without provisioning or managing servers. It is serverless, and will only run when a a POST request is made to API Gateway. Lambda will be responsible for parsing POST requests from walle-ng and publishing SNS messages. In AWS console, go to Lambda and perform the following actions:

Lambda –> Create Function –> Select β€œAuthor from scratch”

In the Basic information section, set the following actions:

  • Function name: walle-ng-lambda
  • Runtime : Python3.6
  • Role Name : walle-ng-role
  • Permissions : Basic Lambda, Amazon SNS publish policy
  • Click –> Create Function

Once the Lambda function is created, scroll down to the Function code section and copy/paste the code below into the lambda_function.py script. Under TOPIC_ARN_SMS, change the value to the ARN you noted when you created the walle-ng-topic. For this example, would be changed to arn:aws:sns:us-east-1:646789677679:walle-ng-topic.

When done, click –> Save.

import boto3
import urllib.parse
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

TOPIC_ARN_SMS = "<sns_topic_arn>"
SMS_SUBJ = "Alert"
SMS_MESG = "Observed unknown person(s)"

'''Setup SNS resource'''
def publish_sms_msg(topic_arn=TOPIC_ARN_SMS, sms_mesg=SMS_MESG, sms_subj=SMS_SUBJ):
sns = boto3.resource('sns')
publish_sms(sns, topic_arn, sms_mesg, sms_subj)

'''Send the SMS'''
def publish_sms(sns, topic_arn, sms_mesg, sms_subj):
topic = sns.Topic(topic_arn)
topic.publish(Message=sms_mesg, Subject=sms_subj)

'''Event handler'''
def lambda_handler(event, context):
if event['httpMethod'] == 'POST':
msg = event['body']
msg = urllib.parse.parse_qs(msg)
if msg['message']:
alert = msg['message'][0]
logger.info(alert)
publish_sms_msg(sms_mesg=alert)
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json'
},
'body': 'OK'
}
else:
return {
'statusCode': 499,
'headers': {
'Content-Type': 'application/json'
},
'body': 'Go Away!'
}
else:
return {
'statusCode': 499,
'headers': {
'Content-Type': 'application/json'
},
'body': 'Go Away!'
}

Source: Face Tracking and Identification Using Walle-ng


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top