1

enter image description here

When I detect some faces in the upper picture(sonicyouth.jpg), one of them is slant .When use harr-like features to detect them.Only 3 faces can be recognized, the female one is omitted.The code as follows:

import cv2
import sys

imagePath = "sonicyouth.jpg"
cascPath = "haarcascade_frontalface_default.xml"
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.05,
    minNeighbors = 8,
    minSize=(30, 30),
    # flags = cv2.cv.CV_HAAR_SCALE_IMAGE
    flags = cv2.CASCADE_SCALE_IMAGE|cv2.CASCADE_FIND_BIGGEST_OBJECT|cv2.CASCADE_DO_ROUGH_SEARCH
)

print("Found {0} faces!".format(len(faces)))

The result is "Found 3 faces!".How can I perform the detection result?With RCNN or sth. else?Especially to the rotation face.

markalex
  • 8,623
  • 2
  • 7
  • 32
Zhilai Liu
  • 13
  • 5
  • I follow the idea form [link]https://stackoverflow.com/a/15997139/12629299 , but only one faces can be detected ,and the detected one is not the **side face**. – Zhilai Liu Dec 31 '19 at 09:44

2 Answers2

2

You are using an old method of face detection algorithm. Haar cascade detection is the first successful face detection algorithm that provide real time detection.

Because it was the first face detection algorithm, it has many constraints. One of them as you point out is the inability to detect rotated faces. It will also be unable to detect side faces as well as occluded faces.

Using newer deeplearning based methods will improve the detection rate. OpenCV provide those in their new dnn folders. You can refer to this link for better tutorials.

But if you want to stick to Haar Cascade, you can do an old trick by rotating the image 45 degree and run the same detection algorithm again. This time you will be able to find the missing head and combine the result!

yapws87
  • 1,809
  • 7
  • 16
  • But when the image rotated,the original untitled image can not be detected successfully. It's a dilemma. – Zhilai Liu Dec 31 '19 at 09:44
  • You need to run the algorithm twice. Once on the original image and once on the rotated image and combine the results. That was how it was done before the emergence of deeplearning algorithms. – yapws87 Dec 31 '19 at 12:11
1

Face Recognition and Face Detection are different! :)

If you just want to detect, use the RetinaFace which is the state-of-the-art

ref: https://paperswithcode.com/sota/face-detection-on-wider-face-hard

If you want to recognize(verify or identify), use the ArcFace which is the state-of-the-art

ref: https://paperswithcode.com/sota/face-verification-on-megaface ref: https://paperswithcode.com/sota/face-identification-on-megaface

Chanran Kim
  • 439
  • 3
  • 8