Brainy Pi

Available to select audience (currently beta)

Face recognition on brainy pi
In today’s technology-driven world, face recognition technology gained immense popularity due to its numerous applications in various domains. From security systems to social media platforms, face recognition technology is everywhere. OpenCV, a powerful open-source computer vision library, revolutionized the development of face recognition applications by providing tools and algorithms for efficient image processing. In this blog, we will delve deeper into the face recognition using Opencv on BrainyPi, an innovative platform that allows developers to create intelligent systems with ease. We will explore the various aspects of face recognition, including detection, recognition, and tracking, and how OpenCV makes it possible to create robust and accurate face recognition applications.
Face recognition using OpenCV and face recognition library in Python involves several steps:
  1. Face detection: The first step in face recognition is to detect the face in the image. For this we used Haar Cascade Classifier, which is a pre-trained classifier that can detect faces in an image.
  2. Face alignment: Once the face is detected, we need to be align it in a standard format for further processing. We do this by locating the facial landmarks on the face, such as the eyes, nose, and mouth, and then applying an affine transformation to align the face.
  3. Feature extraction: Next, we extract features from the aligned face. These features are unique to each face and  used to distinguish one face from another. The face recognition library uses deep neural networks to extract these features.
  4. Face matching: Finally, the extracted features are compared to a database of known faces to identify the person in the image. We do this using algorithms such as k-nearest neighbors or support vector machines.

A little about source code

The source code contains three python files
  1. registerFace.pyfile is to register the face of the user. First the user has to enter their name and then stand in front of the camera and press space key to store the image.
  2. faceRecognition.pyfile is the main file of the program. When this file  runs it opens up the camera and then tries to match the face in the camera to the faces stored the dataset.
  3. faceRecUtils.py file is where the actual recognition happens. faceRecognition.py file calls the methods inside this file and then we pass the image through the recogniseFace function. Finally we pass the output to the faceRecognition.py file and then we display the output on the screen.

Running the Code

To run the face recognition program on BrainyPi, follow these steps:
  1. Connect USB webcam to BrainyPi.
  2. Clone the GitHub Repository
    git clone https://github.com/brainypi/brainypi-opencv-examples.git 
  3. Install Required Dependencies
    cd face-recognition
    sudo apt install python3-dev cmake
    pip install -r requirements.txt
  4. Register Your Face
    Before running face recognition, you need to register your face by running the registerFace.py file:
    python registerFace.py
    When you run the program, you’ll get a prompt to enter your name and then stand in front of the camera and press the space key to store the image.
  5. Run Face Recognition
    After registering your face, you can run the faceRecognition.py file to start face recognition:
    python faceRecognition.py
    The program will open up the camera and try to match the face in the camera to the faces stored in the dataset. The output will be displayed on the screen. To exit the program, press the q key.

Adapting the Code for Your Own Use

If you want to use this face recognition code for your own project, you’ll need to make some changes to customize it for your specific use case. Here are some tips for adapting the code:
  1. recogniseFace() function inputs and outputs are
    • Inputs:
      1. inputImage [OpenCV Mat]: Input Image in OpenCV format
      2. data [list]: Face Embeddings generated by registerFace.py
      3. currentname [str]: Default name, i.e if the face is not recognized then it will use this name.
    • Outputs:
      1. name [str]: List of Names of the faces recognized |
      2. frame [OpenCV Mat]: Input image with face marked and names printed
  2. You can use this function by importing faceRecUtils.py file
    import faceRecUtils
     
    # ... After some code 
    
    names, frame = faceRecUtils.recogniseFace(frame, data, currentname)
  3. You can use the example code given here – https://github.com/brainypi/brainypi-opencv-examples/blob/main/face-recognition/faceRecongition.py

EndNotes

In this blog post, we explored the face recognition using opencv on BrainyPi, a powerful and affordable single-board computer. We learned about the steps involved in face recognition using OpenCV and saw how to run the face recognition program on BrainyPi. With the increasing popularity of face recognition technology, it’s important to stay up to date with the latest developments in this field, and OpenCV makes it easy to do so.
0 Comments

Leave a reply

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

*