开始使用免费开始使用

多个人脸

在本练习中,您将检测图像中的多个人脸,并将它们分别显示。可以把它看作是为您自己的朋友收集人脸数据集的一种方法!

A group of 7 friends
图像已预加载为 friends_image

feature 模块中的分类器级联类 Cascade 已经导入,同时还导入了用于在图像中标出人脸并裁剪以便单独显示的函数 show_detected_face()

本练习是课程的一部分

Python 图像处理

查看课程

练习说明

  • data 模块加载已训练文件 .lbp_frontal_face_cascade_filename()
  • 使用该已训练文件初始化检测器级联。
  • 在图像中检测人脸,并将 scale_factor 设为 1.2、step_ratio 设为 1。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load the trained file from data
trained_file = ____.___()

# Initialize the detector cascade
detector = ____

# Detect faces with scale factor to 1.2 and step ratio to 1
detected = detector.____(img=friends_image,
                                       scale_factor=____,
                                       step_ratio=____,
                                       min_size=(10, 10),
                                       max_size=(200, 200))
# Show the detected faces
show_detected_face(friends_image, detected)
编辑并运行代码