Python Forum
How to create python API for face_recognition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create python API for face_recognition
#1
Hi,
I am using python 3.6.I have created a face recognition model using Anaconda python and want to create a API service using Flask or any API service.Could you please help me on this.Basically this code will take the input from the user and identify the face and will provide the output as image matched or not with the trained images.


I just want to create a python API for this.I have googled and read in many forums but didn't get help to create a python API for face recognition.Thanks in advance for you help.

This is the code for the same:

import tensorflow
#import keras
import cv2
import face_recognition
import os
#from sklearn2pmml.pipeline import PMMLPipeline

images = os.listdir('C:/Users/vaddm/Documents/Murali/AI_COE/face_recognition/images')

# load your image
image_to_be_matched = face_recognition.load_image_file('C:/Users/vaddm/Documents/Murali/AI_COE/face_recognition/user_aadhar.jpg')
# encoded the loaded image into a feature vector
image_to_be_matched_encoded = face_recognition.face_encodings(
    image_to_be_matched)[0]

# iterate over each image
for image in images:
    # load the image
    current_image = face_recognition.load_image_file("C:/Users/vaddm/Documents/Murali/AI_COE/face_recognition/images/" + image)
    # encode the loaded image into a feature vector
    current_image_encoded = face_recognition.face_encodings(current_image)[0]
    # match your image with the image and check if it matches
    result = face_recognition.compare_faces(
        [image_to_be_matched_encoded], current_image_encoded)
    # check if it was a match
    if result[0] == True:
        print ("Matched: " + image)
    else:
        print ("Not matched: " + image)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020