Bounding boxes returned without detected face image in dlib python

Solved!There are edge cases where original rectangle is partially outside the image window. That happens with dlib. So, instead of

  • detected_face = img[top:bottom, left:right],

the detected face should be

  • detected_face = img[max(0, top): min(bottom, img_height), max(0, left): min(right, img_width)]