使用Dlib'检测多个面;使用python的人脸检测器

使用Dlib'检测多个面;使用python的人脸检测器,python,image,dlib,Python,Image,Dlib,下面是用于检测图像中单个人脸的代码,但问题是,如果图像中有多个人脸,则只需要第一个。请建议 import caffe, dlib, io from __future__ import print_function import os import matplotlib.pyplot as plt detector = dlib.get_frontal_face_detector() img21 = 'group.jpg' im_name = img21 img = io.imread(os.p

下面是用于检测图像中单个人脸的代码,但问题是,如果图像中有多个人脸,则只需要第一个。请建议

import caffe, dlib, io
from __future__ import print_function
import os
import matplotlib.pyplot as plt

detector = dlib.get_frontal_face_detector()
img21 = 'group.jpg'
im_name = img21
img = io.imread(os.path.join('./',im_name))
faces=[]
faces= detector(img)
total= len(faces)
print('total faces here :',total)
cropped_face = input_image_cropped[faces[0].top():faces[0].bottom(),
faces[0].left():faces[0].right(), :]
input_image_cropped = caffe.io.load_image(os.path.join('./', im_name))  
cropped_face = input_image_cropped[faces[0].top():faces[0].bottom(), 
faces[0].left():faces[0].right(), :]
h = faces[0].bottom() - faces[0].top()
w = faces[0].right() - faces[0].left()
age_prediction_cropped = age_net.predict([cropped_face])
print('\n\t   predicted age (Dlib-cropped image):',
age_prediction_cropped[0].argmax())
plt.show()
供参考: 我删除了代码中不需要的其他部分

我通过下面的链接,但我不能运行所有检测到的脸循环?请建议我如何为所有检测到的人脸运行循环。

通过以下更改,问题得以解决

对于枚举中的i,d(面):
裁剪的\u面=输入的\u图像\u裁剪的[d.top():d.bottom(),d.left():d.right(),:] input_image_crapped=caffe.io.load_image(os.path.join('./',im_name))
裁剪的\u面=输入的\u图像\u裁剪的[d.top():d.bottom(),d.left():d.right(),:]