【发布时间】:2017-06-01 14:51:10
【问题描述】:
以下是用于检测图像中单个人脸的代码,但问题是如果图像中有多个人脸,则只需要第一个。请建议
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()
仅供参考: 我剥离了其他不需要的代码部分。
我通过下面的链接,但我无法为所有检测到的面孔运行循环?请建议我如何为所有检测到的人脸运行循环。 http://dlib.net/face_detector.py.html
【问题讨论】: