【问题标题】:Detect multiple faces using Dlib's face detector using python使用 python 使用 Dlib 人脸检测检测多个人脸
【发布时间】: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

【问题讨论】:

    标签: python image dlib


    【解决方案1】:

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

    for i, d in enumerate(faces):
    cropped_face = input_image_cropped[ d.top():d.bottom(), d.left():d.right(), :] input_image_cropped = caffe.io.load_image(os.path.join('./', im_name))
    cropped_face = input_image_cropped[d.top():d.bottom(), d.left():d.right(), :]

    【讨论】:

      猜你喜欢
      • 2020-10-24
      • 2017-10-18
      • 2017-07-19
      • 2017-01-18
      • 2021-03-22
      • 2016-07-16
      • 2019-11-18
      • 1970-01-01
      • 2017-02-01
      相关资源
      最近更新 更多