Anurag Krishnan
Anurag Krishnan

Reputation: 3

Integrating Python Code with Flutter for Facial Recognition Using face_recognition Library

I'm currently working on a Flutter project where I need to integrate Python code for facial recognition. Specifically, I want to utilize the face_recognition library within my Python code. My requirements are as follows

  1. I need to embed Python code within my Flutter project.
  2. I'm exploring the feasibility of using the face_recognition library for facial recognition and comparing with two images.
  3. The application need to work in offline ,which means no api calling is allowed.

Below is an example snippet of the Python code I intend to use:

import face_recognition
import sys
def faceRecFun(image1_path, image2_path):
   
    try:
        image1 = face_recognition.load_image_file(image1_path)
        image2 = face_recognition.load_image_file(image2_path)
        
        face_encoding1 = face_recognition.face_encodings(image1)[0]
        face_encoding2 = face_recognition.face_encodings(image2)[0]
        results = face_recognition.compare_faces([face_encoding1], face_encoding2)
        
        return results[0]
    except Exception as e:
        return False
if __name__ == "__main__":
    # Check if the correct number of arguments are provided
    if len(sys.argv) != 3:
        print(False)
        sys.exit(1)
    if sys.argv[1] == "" or sys.argv[2] == "" :
        print(False)
        sys.exit(1)    

  
    arg1 = sys.argv[1]
    arg2 = sys.argv[2]
 
    print(faceRecFun(str(arg1), str(arg2)))

# # # Example usage:
# image1_path = "C:/Documents/Scraps/Asset/0.jpeg"
# image2_path = "C:/Documents/Scraps/Asset/1.jpeg"
# faces_match = faceRec.faceRecFun(image1_path, image2_path)
# print("Faces match:", faces_match)

I need to call the above function from my flutter project and will send two paths of image which contain single face in it. That will return True or False based on the similarity.

String result=await faceRecFun(file.path,file1.path);

I would appreciate any guidance or examples on how to achieve this integration and whether it's feasible to utilize the face_recognition library within a Flutter project.

Or it is okay if any other way available on this. Like a flutter package or library. But the comparison should be proper.

Thank you in advance for your assistance!

Upvotes: 0

Views: 307

Answers (0)

Related Questions