Skip to content

手部检测 ​

声明实例 ​

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

python
hand_detection = HandDetection(0)
# 有多个实例时
hand_detection_1 = HandDetection(1)

参数 ​

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

设置摄像头 ​

设置用于手部检测的摄像头。

device

参数 ​

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

Python ​

python
hand_detection = HandDetection(0)

hand_detection.device('')

加载手部模型 ​

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

load_model

参数 ​

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

Python ​

python
hand_detection = HandDetection(0)

hand_detection.load_model(wait=True)

设置检测目标 ​

决定检测手部时,是以单手为准还是以双手为准。

max_hands

参数 ​

名称类别说明范围 / 种类默认值
unit下拉选项手的数量单手(one), 双手(both)-

Python ​

python
hand_detection = HandDetection(0)

hand_detection.max_hands('one')
hand_detection.max_hands('both')

检测一次手部 ​

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

detect_once

参数 ​

(无)

Python ​

python
hand_detection = HandDetection(0)

hand_detection.detect_once()

开始 / 停止持续手部检测 ​

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

detect_continuous

参数 ​

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

Python ​

python
hand_detection = HandDetection(0)

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

显示结果 ​

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

display

参数 ​

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

Python ​

python
hand_detection = HandDetection(0)

hand_detection.display(True)
hand_detection.display(False)

手部部位的位置 ​

返回指定手的手掌 / 手腕位置信息。

hand_data

参数 ​

名称类别说明范围 / 种类默认值
side下拉选项手的方向左侧(left), 右侧(right)-
unit下拉选项手部部位手掌(palm), 手腕(wrist)-
pos下拉选项坐标 / 大小种类x, y-

Python ​

python
hand_detection = HandDetection(0)

hand_detection.hand('left', 'palm', 'x')
hand_detection.hand('right', 'wrist', 'y')
hand_detection.hand('left', 'hand', 'min_x')
hand_detection.hand('right', 'palm', 'width')

手指关节的位置 ​

返回指定手指的关节坐标。

joint_data

参数 ​

名称类别说明范围 / 种类默认值
side下拉选项手的方向左侧(left), 右侧(right)-
unit下拉选项手指拇指(thumb), 食指(index), 中指(middle), 无名指(ring), 小指(pinky)-
joint下拉选项关节位置第一关节(first), 第二关节(second), 第三关节(third), 指尖(last)-
pos下拉选项坐标x, y-

Python ​

python
hand_detection = HandDetection(0)

hand_detection.finger('left', 'index', 'first', 'x')
hand_detection.finger('right', 'thumb', 'last', 'y')

手部矩形信息 ​

返回指定手部区域矩形的位置 / 大小值。

hand_square

参数 ​

名称类别说明范围 / 种类默认值
side下拉选项手的方向左侧(left), 右侧(right)-
unit下拉选项手部部位手(hand), 手掌(palm)-
pos下拉选项矩形信息最小 x 坐标(min_x), 最大 x 坐标(max_x), 最小 y 坐标(min_y), 最大 y 坐标(max_y), 宽(width), 高(height), 面积(area)-

Python ​

python
hand_detection = HandDetection(0)

hand_detection.hand('left', 'hand', 'min_x')
hand_detection.hand('right', 'palm', 'width')

手与手之间的距离 ​

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

hand_to_hand_distance

参数 ​

名称类别说明范围 / 种类默认值
unit1输入值(字符串)第一个手部部位手: 'side_unit' (例: 'left_palm')。side=left/right, unit=palm/wrist/hand-
unit2输入值(字符串)第二个手部部位手: 'side_unit' (例: 'right_palm')。side=left/right, unit=palm/wrist/hand-
type下拉选项距离种类距离(省略或 None), 水平距离(horizontal), 垂直距离(vertical)None

Python ​

python
hand_detection = HandDetection(0)

# 手 ↔ 手 / 距离
hand_detection.get_distance('left_palm', 'right_palm')

手与手指之间的距离 ​

返回手部部位与手指关节之间的距离。

hand_to_joint_distance

参数 ​

名称类别说明范围 / 种类默认值
unit1输入值(字符串)第一个部位手: 'side_unit' (例: 'left_palm')。side=left/right, unit=palm/wrist/hand-
unit2输入值(字符串)第二个部位手指: 'side_unit_joint' (例: 'right_index_first')。unit=thumb/index/middle/ring/pinky, joint=first/second/third/last-
type下拉选项距离种类距离(省略或 None), 水平距离(horizontal), 垂直距离(vertical)None

Python ​

python
hand_detection = HandDetection(0)

# 手 ↔ 手指关节 / 水平距离
hand_detection.get_distance('left_palm', 'right_index_first')

手指与手指之间的距离 ​

返回两个手指关节之间的距离。

joint_to_joint_distance

参数 ​

名称类别说明范围 / 种类默认值
unit1输入值(字符串)第一个部位手指: 'side_unit_joint' (例: 'left_thumb_last')。unit=thumb/index/middle/ring/pinky, joint=first/second/third/last-
unit2输入值(字符串)第二个部位手指: 'side_unit_joint' (例: 'right_index_first')。unit=thumb/index/middle/ring/pinky, joint=first/second/third/last-
type下拉选项距离种类距离(省略或 None), 水平距离(horizontal), 垂直距离(vertical)None

Python ​

python
hand_detection = HandDetection(0)

# 手指关节 ↔ 手指关节 / 垂直距离
hand_detection.get_distance('left_thumb_last', 'right_index_first', 'vertical')

手部模型加载状态 ​

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

model_state

参数 ​

(无)

Python ​

python
hand_detection = HandDetection(0)

hand_detection.model_state()

检测到手部? ​

是否找到了手

detected

参数 ​

(无)

Python ​

python
hand_detection = HandDetection(0)

hand_detection.detected()