pythondlib

why my dlib.get_frontal_face_detector()'s output(rectangles[]) is empty?


I try to use Dlib shape_predictor_68_landmark to mark my photos. I use OpenCV to read and resize photos(all of photos are portrait photographs capture from a video). Then I use those processed photos to run the function dlib.get_frontal_face_detector().

Here is my code:

detector=dlib.get_frontal_face_detector()
for filename in os.listdir("/content/drive/MyDrive/new"):
  frame = cv2.imread("/content/drive/MyDrive/new/" + filename)
  frame = cv2.resize(frame, (720, 720), interpolation=cv2.INTER_NEAREST)
  faces = detector(frame, 0) 
  print('File name:',filename)
  print('Face=',faces)

the faces = detector(frame, 0) should output a rectangles[], but when I print it for check, its output turn out to be an empty rectangles[]. the result(partly) is below:

File name: frame_484.jpg
Face= rectangles[]

I don't know how to let it output a correct output(in other words, a not empty rectangles[]).


Solution

  • The model outputs no rectangles which means the model is unable to detect any face in the given image but there are things which you can try to improve the results:

    If all these doesn't work then you can try dlib's CNN module which has far better accuracy than frontal_face module dlib.cnn_face_detection_model_v1