Skip to content

人脸检测 ​

声明实例 ​

把人脸检测(FaceDetection) 积木添加到工作区后,Python 代码中会自动插入下面这样的实例声明:

python
face_detection = FaceDetection(0)
# 有多个实例时
face_detection_1 = FaceDetection(1)

参数 ​

名称类别说明范围 / 种类默认值
index下拉选项实例编号(从 0 开始)0 以上的整数0

设置摄像头 ​

设置用于人脸检测的摄像头。

device

参数 ​

名称类别说明范围 / 种类默认值
unit下拉选项摄像头设备名称系统摄像头标签-

Python ​

python
face_detection = FaceDetection(0)

face_detection.device('')

加载人脸模型 ​

加载训练好的人脸模型。要使用「人脸检测」模块的功能,必须先完成这一步。

load_model

参数 ​

名称类别说明范围 / 种类默认值
wait复选框是否等待加载完成TRUE / FALSETRUE

Python ​

python
face_detection = FaceDetection(0)

face_detection.load_model(wait=True)

检测一次人脸 ​

找出当前画面中的人脸,只标示一次。

detect_once

参数 ​

(无)

Python ​

python
face_detection = FaceDetection(0)

face_detection.detect_once()

开始 / 停止持续人脸检测 ​

持续跟踪当前画面中的人脸,并在画面上标示出来。

detect_continuous

参数 ​

名称类别说明范围 / 种类默认值
unit下拉选项动作开始(start), 停止(stop)-

Python ​

python
face_detection = FaceDetection(0)

# unit = "start"
face_detection.detect_continuous()
# unit = "stop"
face_detection.stop()

显示结果 ​

决定是否在摄像头画面上显示人脸检测的结果。

display

参数 ​

名称类别说明范围 / 种类默认值
on下拉选项显示 ON / OFF显示(on=True), 隐藏(off=False)TRUE

Python ​

python
face_detection = FaceDetection(0)

face_detection.display(True)
face_detection.display(False)

人脸部位的位置 ​

返回人脸或人脸各部位的位置坐标。

face_data

参数 ​

名称类别说明范围 / 种类默认值
unit下拉选项人脸部位人脸(face), 左眼(left eye), 右眼(right eye), 左耳(left ear), 右耳(right ear), 鼻子(nose), 嘴(mouth)-
pos下拉选项坐标种类x, y-

Python ​

python
face_detection = FaceDetection(0)

face_detection.face('x')
face_detection.left_eye('y')
face_detection.right_eye('x')
face_detection.left_ear('x')
face_detection.right_ear('y')
face_detection.nose('x')
face_detection.mouth('y')

人脸矩形框信息 ​

返回人脸区域矩形框的位置 / 大小值。

face_square

参数 ​

名称类别说明范围 / 种类默认值
pos下拉选项矩形框信息最小 x 坐标(min_x), 最大 x 坐标(max_x), 最小 y 坐标(min_y), 最大 y 坐标(max_y), 宽(width), 高(height), 面积(area)-

Python ​

python
face_detection = FaceDetection(0)

face_detection.face('min_x')
face_detection.face('width')
face_detection.face('area')

两个部位之间的距离 ​

返回人脸两个部位之间的距离。

distance

参数 ​

名称类别说明范围 / 种类默认值
unit1下拉选项第一个部位face, left_eye, right_eye, left_ear, right_ear, nose, mouth-
unit2下拉选项第二个部位face, left_eye, right_eye, left_ear, right_ear, nose, mouth-
type下拉选项距离种类距离(省略或 None), 水平距离(horizontal), 垂直距离(vertical)None

Python ​

python
face_detection = FaceDetection(0)

face_detection.get_distance('left_eye', 'right_eye')  # 距离
face_detection.get_distance('left_eye', 'right_eye', 'horizontal')  # 水平距离
face_detection.get_distance('nose', 'mouth', 'vertical')  # 垂直距离

人脸模型加载状态 ​

返回人脸模型的加载状态。
还没有加载时返回 0,正在加载时返回 1,加载完成时返回 2。

model_state

参数 ​

(无)

Python ​

python
face_detection = FaceDetection(0)

face_detection.model_state()

检测到人脸? ​

是否找到了人脸

detected

参数 ​

(无)

Python ​

python
face_detection = FaceDetection(0)

face_detection.detected()