I have roughly 5000 photographs of various persons that I am organising according to the person. As a result, I intend to develop a Python script to carry out the task. I'm new to the Opencv library and am unsure whether this is feasible to do. To locate the faces in the photos, I wrote the code below.
import cv2
def find_faces(imagePath,results_path):
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,scaleFactor=1.3,minNeighbors=3,minSize=(30, 30))
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
roi_color = image[y:y + h, x:x + w]
roi_gray = gray[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
if len(eyes) >= 2:
cv2.imwrite(results_path + str(w) + str(h) + '_faces.jpg', roi_color)
Now I need to organise the photographs per person.Any help with the next steps is greatly appreciated.