i am creating a dataset for real time face recognition using python. i want it should intimate if the image already available in dataset. how to implement in opencv?
.
import cv2
from PIL import Image
import os
import time
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
ds_factor = 0.6
font = cv2.FONT_HERSHEY_SIMPLEX
dir_path = "static/capture_image"
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
output = image.copy()
cv2.rectangle(image, (400, 300), (800, 600), (255, 255, 255), 2)
cv2.addWeighted(image, 0.5, output, 1 - .5, 0, output)
cv2.resize(output, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)
roi = gray[300:600, 400:800] # ymin,ymax, xmin,xmax !
faces = face_cascade.detectMultiScale(
roi, scaleFactor=1.1,
minNeighbors=5,
minSize=(200, 200),
flags=cv2.CASCADE_SCALE_IMAGE)
for (x, y, w, h) in faces:
cv2.rectangle(output, (x + 400, y + 300), (x + 400 + w, y + 300 + h), (255, 0, 0), 3)
cv2.putText(output, 'Number of Faces : ' + str(len(faces)), (40, 40), font, 1, (255, 0, 0), 2)
face_image = gray[y+300:y + 300 + h, x + 400:x + 400 + w]
pil_image = Image.fromarray(face_image)
File_Formatted = ("%s" % (y+300)) + ".jpg"
file_path = os.path.join(dir_path, File_Formatted)
pil_image.save(file_path)
break
ret, jpeg = cv2.imencode('.jpg', output)
return jpeg.tobytes()
what does this mean ?
read "to intimate" as "to reveal/indicate".
as for the subject: you would have to recognize subjects. you can do that by teaching the system a subject from sample faces, or you can let it collect faces and figure out which faces are very similar and which faces aren't (a clustering problem). this problem is harder than simply collecting faces as you do.
I am creating a dataset for face recognition using python. Then i want to validate if the face is already available in the dataset or it is the new one. If it is the new face I want the text box to enter his/her name and details. If it is already available need to show the pop up like "the face is already available".
look at facenet or other face recognition methods (eigenfaces, fisher faces). you need to formulate a similarity/distance measure on faces.