I watched a YouTube video about face recognition and done same as that he told.But at the time of face recognition it recognise all the peoples as same.what is the reason.code is
import cv2
def draw_boundary(img, classifier, scaleFactor, minNeighbors, color, text, clf):
# Converting image to gray-scale
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# detecting features in gray-scale image, returns coordinates, width and height of features
features = classifier.detectMultiScale(gray_img, scaleFactor, minNeighbors)
coords = []
# drawing rectangle around the feature and labeling it
for (x, y, w, h) in features:
cv2.rectangle(img, (x,y), (x+w, y+h), color, 2)
# Predicting the id of the user
id, _ = clf.predict(gray_img[y:y+h, x:x+w])
# Check for id of user and label the rectangle accordingly
if id==1:
cv2.putText(img, "cat", (x, y-4), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 1, cv2.LINE_AA)
coords = [x, y, w, h]
return coords
# Method to recognize the person
def recognize(img, clf, faceCascade):
color = {"blue": (255, 0, 0), "red": (0, 0, 255), "green": (0, 255, 0), "white": (255, 255, 255)}
coords = draw_boundary(img, faceCascade, 1.1, 10, color["white"], "Face", clf)
return img
# Loading classifier
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Loading custom classifier to recognize
clf = cv2.face.LBPHFaceRecognizer_create()
clf.read("classifier.yml")
# Capturing real time video stream. 0 for built-in web-cams, 0 or -1 for external web-cams
video_capture = cv2.VideoCapture(-1)
while True:
# Reading image from video stream
_, img = video_capture.read()
# Call method we defined above
img = recognize(img, clf, faceCascade)
# Writing processed image in a new window
cv2.imshow("face detection", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# releasing web-cam
video_capture.release()
# Destroying output window
cv2.destroyAllWindows()