Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Facial Recognition Feature Issue No. #298 #299

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bridges/python/addface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import cv2
import os
import smtplib
import datetime
name=input("Name: ")
camera = cv2.VideoCapture(0)
return_value, image = camera.read()
date_string = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
cv2.imwrite(os.path.join('/' , name+'.jpg'), image)
print(os.path.join('/' , name+'.jpg'))
33 changes: 33 additions & 0 deletions bridges/python/facerecog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import face_recognition
import numpy as np
import cv2
import os
import smtplib
try:
for file in os.listdir("D:\Leon"):
filename = os.fsdecode(file)
if filename.endswith(".jpg"):
print(filename)
imgloaded=face_recognition.load_image_file(filename)
imgloaded=cv2.cvtColor(imgloaded,cv2.COLOR_BGR2RGB)
camera = cv2.VideoCapture(0)
return_value, image = camera.read()
cv2.imwrite(os.path.join('/' , 'testimage.jpg'), image)
imgtest=face_recognition.load_image_file('/testimage.jpg')
imgtest=cv2.cvtColor(imgtest,cv2.COLOR_BGR2RGB)
faceloc=face_recognition.face_locations(imgloaded)[0]
encodeloaded=face_recognition.face_encodings(imgloaded)[0]
cv2.rectangle(imgloaded,(faceloc[3],faceloc[0]),(faceloc[1],faceloc[2]),(255,0,255),2)
faceloctest=face_recognition.face_locations(imgtest)[0]
encodetest=face_recognition.face_encodings(imgtest)[0]
cv2.rectangle(imgtest,(faceloc[3],faceloc[0]),(faceloc[1],faceloc[2]),(255,0,255),2)
results=face_recognition.compare_faces([encodeloaded],encodetest)
if(results[0]):
print(filename.replace(".jpg","")," Verified")
else:
print("Verification Failed")


except OSError as e:
print(e)
print("Error In Loading File")
2 changes: 2 additions & 0 deletions bridges/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from json import dumps, loads
from importlib import import_module


def main():
"""Dynamically import modules related to the args and print the ouput"""

Expand All @@ -17,4 +18,5 @@ def main():
return getattr(m, queryobj['action'])(queryobj['query'], queryobj['entities'])

if __name__ == '__main__':
#Appropriately adding Face recognition modules in the main python file.
main()