How to intimate face not found in real time face detection project using opencv

while True:
   
    frames = pipeline.wait_for_frames()
    color_frame = frames.get_color_frame()

    # Convert depth_frame to numpy array to render image in opencv
    img = np.asanyarray(color_frame.get_data())
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        print(x, y, w, h)
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        try:
            id, confidence = model.predict(gray[y :y + h, x :x + w])
            if confidence < 100:
                id = names[id]
                confidence = "  {0}%".format(round(100 - confidence))
            else:
                id = "unknown"
                confidence = "  {0}%".format(round(100 - confidence))
            cv2.putText(img, str(id), (x + 5, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
            cv2.putText(img,
                        str(confidence),
                        (x + 5, y + h - 5),
                        cv2.FONT_HERSHEY_SIMPLEX,
                        1, (0, 0, 255), 2)
        except:
            cv2.putText(img, "Face not Found", (40, 40), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
            pass

    cv2.imshow(window_name, img);
    key = cv2.waitKey(1)
    # if pressed escape exit program
    if key == 27:
        cv2.destroyAllWindows()
        break
if len(faces)==0:
    cv2.putText(img, "Not found", (40, 40), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)
else:
    for (x, y, w, h) in faces:
        ...
1 Like

thanks for your reply.

how to restrict duplicate face or fake face recognition at the same time intimate the face not found.

did you mean: imitate ?

Intimate means the duplicate face enter in inside of camera it should intimate as the face not found in the real time face recognition.

1 Like

if the question was: how to inprove the face recognition, then:

  • have enough images (20+ per person)
  • control the lighting in the images, make it as similar as possible to the test situation
  • proper cropping, the less background, the better
  • proper alignment (e.g. from facial landmarks)
  • try a different recognition mechanism, e.g. the OpenFace dnn