This function is used to match the input image from the stage with the stored classes previously stored in the database.
The function also stores all the face data in PictoBlox for access by other functions.
Function Definition: recognisefromstage()
This function is used to match the input image from the stage with the stored classes previously stored in the database.
The function also stores all the face data in PictoBlox for access by other functions.
The example demonstrates the application of face recognition with stage. Following are the key steps happening:
sprite = Sprite('Square Box')
fd = FaceDetection()
import time
fd.setthreshold(0.5)
fd.enablebox()
# Reset Database
fd.deleteallclass()
# Adding Chirs face to database
sprite.switchbackdrop("Chris")
time.sleep(0.5)
fd.addclassfromstage(1, "Chris")
# Adding Robert face to database
sprite.switchbackdrop("Robert")
time.sleep(0.5)
fd.addclassfromstage(2, "Robert")
sprite.switchbackdrop("Robert and Chris")
while True:
fd.recognisefromstage()
print(fd.count())
for i in range(fd.count()):
sprite.setx(fd.x(i+1))
sprite.sety(fd.y(i+1))
sprite.setsize(fd.width(i+1))
sprite.say(getclassname(i+1))
time.sleep(1)
The project uses face recognition to identify authorized people and opens the door accordingly.
We are using 2 devices in this project:
We will be using Face Detection extension for making the face recognition application.
This code is used to add a new face to a system:
#Create a new Sprite object with the name 'Tobi'
sprite = Sprite('Tobi')
#Create a new Face Detection object
fd = FaceDetection()
#Import the time library
import time
#Set the threshold for face detection to 0.5
fd.setthreshold(0.5)
#Turn off the video feed from the camera
fd.video("off", 0)
#Enable the box to be drawn around the detected face
fd.enablebox()
#Define a function that adds a new face to the system
def addFace():
#Create a flag to keep track if a new face has been added
faceFlag = 0
#Turn on the video feed from the camera
fd.video("on", 0)
time.sleep(1)
#Keep looping until a new face has been added
while faceFlag == 0:
#Analyse the camera for a face
fd.analysecamera()
#Check if one face has been detected
if fd.count() == 1:
#Ask the user which slot the face should be added to
sprite.input("Select the slot (1 to 10)?")
#Store the slot number the user provided
faceSlot = sprite.answer()
#Ask the user to enter a name for the new face
sprite.input("Enter the name of the face")
#Store the name the user provided
faceName = sprite.answer()
#Add the face to the system with the provided slot number and name
fd.addclassfromcamera(faceSlot, faceName)
#Set the faceFlag to 1 to stop the loop
faceFlag = 1
#Turn off the video feed from the camera
fd.video("off", 0)
#Keep running the loop forever
while True:
#Check if the 'a' key has been pressed
if sprite.iskeypressed("a"):
#If yes, call the addFace() function
addFace()
An Infrared sensor is a type of sensor that senses if something is close to it or not. The IR stands for Infrared sensor. Infrared is the light out of our visible spectrum.
An IR sensor has a white LED (transmitter) and a photodiode (receiver). The transmitter emits IR light, and the receiver detects reflected light from objects within the sensor’s range, which can be adjusted with a potentiometer. The sensor is indicated by two LED indicators, a power LED which is always on, and a signal LED which is on when an object is detected and off when nothing is detected.
The signal LED has two states or situations:
This code creates a program that can add a new face to the system, and then recognize and authenticate the user:
#Create a new Sprite object with the name 'Tobi'
sprite = Sprite('Tobi')
#Create a new Face Detection object
fd = FaceDetection()
#Import the time library
import time
#Create a new Quarky object
quarky = Quarky()
#Create a new Expansion object
expansion = Expansion()
house = IoTHouse()
#Set the threshold for face detection to 0.5
fd.setthreshold(0.5)
#Turn off the video feed from the camera
fd.video("off", 0)
#Enable the box to be drawn around the detected face
fd.enablebox()
#Move a servo on the expansion board to position 5 and move it to 100 degrees
expansion.moveservo(5, 100);
#Define a function that adds a new face to the system
def addFace():
#Create a flag to keep track if a new face has been added
faceFlag = 0
#Turn on the video feed from the camera
fd.video("on", 0)
time.sleep(1)
#Keep looping until a new face has been added
while faceFlag == 0:
#Analyse the camera for a face
fd.analysecamera()
#Check if one face has been detected
if fd.count() == 1:
#Ask the user which slot the face should be added to
sprite.input("Select the slot (1 to 10)?")
#Store the slot number the user provided
faceSlot = sprite.answer()
#Ask the user to enter a name for the new face
sprite.input("Enter the name of the face")
#Store the name the user provided
faceName = sprite.answer()
#Add the face to the system with the provided slot number and name
fd.addclassfromcamera(faceSlot, faceName)
#Set the faceFlag to 1 to stop the loop
faceFlag = 1
#Turn off the video feed from the camera
fd.video("off", 0)
#Define a function that authenticates the user
def authenticate():
#Turn on the video feed from the camera
fd.video("on", 0)
time.sleep(1)
#Recognise the face in the camera
fd.recognisefromstage()
#Check if one or more face has been detected
if fd.count() > 0:
#Loop through all the detected faces
for i in range(1, fd.count() + 1):
#Check if the face has been recognised
if fd.getclassname(i) != "unknown":
#Speak out the name of the recognised user
sprite.say("Authorised - " + fd.getclassname(i), 2)
#Turn off the video feed from the camera
fd.video("off", 0)
#Return 1 to indicate the user has been authenticated
return 1
#Turn off the video feed from the camera
fd.video("off", 0)
#Return 0 to indicate the user has not been authenticated
return 0
#Keep running the loop forever
while True:
#Check if the 'a' key has been pressed
if sprite.iskeypressed("a"):
#If yes, call the addFace() function
addFace()
#Check if the space key has been pressed
if house.irstatus("D3"):
#If yes, call the authenticate() function
if authenticate() == 1:
#Move the servo to 0 degrees
expansion.moveservo(5, 0)
time.sleep(2)
#Move the servo back to 100 degrees
expansion.moveservo(5, 100)
Copyright 2024 – Agilo Research Pvt. Ltd. All rights reserved – Terms & Condition | Privacy Policy