Firstly, I am sorry if the title is long. I am working on face detection using python. I am trying to write a script where it will notify user when there is same picture or almost same picture/faces detected between two directories/folder. Below is the script that I wrote so far.
import cv2
import glob, requests
def detect1():
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
for img in glob.glob('/Users/Ling/Pythonfiles/Faces/*.jpg'):
cv_img = cv2.imread(img)
gray = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)
faces1 = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces1:
cv2.rectangle(cv_img,(x,y),(x+w,y+h),(255,0,0),2)
def detect2():
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
for image in glob.glob('/Users/Ling/Pythonfiles/testfolder/*.jpg'):
cv_image = cv2.imread(image)
gray = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY)
faces2 = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces2:
cv2.rectangle(cv_image,(x,y),(x+w,y+h),(255,0,0),2)
def notify():
if detect2 == detect1:
key = "<yourkey>"
sandbox = "<yoursandbox>.mailgun.org"
recipient = "<recipient's email>"
request_url = 'https://api.mailgun.net/v2/{0}/messages'.format(sandbox)
request = requests.post(request_url, auth=('api', key),
data={
'from': '<sender's email',
'to': recipient,
'subject': 'face detect',
'text': 'common face detected'
})
print 'Status: {0}'.format(request.status_code)
print 'Body: {0}'.format(request.text)
There is no error but there is no notification either. I have a folder with 10 pictures of random faces I downloaded it from Google Image(just for learning purpose)and another folder with 2 picture of people that their face is same as the some of the picture in the previous folder. The picture with the same face is in different angle.
I wrote the script by referring to tutorial from https://pythonprogramming.net/haar-cascade-face-eye-detection-python-opencv-tutorial/ and add some line to send the notification if the program detect the same face from both folder.
My question is how do I exactly notify the user if there are same faces detected. I believe this code is incomplete and hoping that someone can give me suggestion on what to add/edit or what I should not write in this script.
Thank you in advance.