Handpose
Handpose 是一种机器学习模型,允许在浏览器中进行手掌检测和手部骨骼手指跟踪。它一次最多可检测一只手,并提供 21 个描述手掌和手指重要位置的 3D 手部关键点。
<html>
<head>
<meta charset="UTF-8" />
<title>Handpose with Webcam</title>
<script src="../p5.dom.min.js"></script> <script src="../p5.min.js"></script>
<script src="../ml5.js"></script>
</head>
<body>
<h1>Handpose with Webcam</h1>
<script src="sketch.js"></script>
</body>
</html>
js代码:
let handpose;
let video;
let predictions = [];
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(width, height);
handpose = ml5.handpose(video, modelReady);
// 这会设置一个填充全局变量“预测”的事件
// 每次检测到新的手部姿势时使用一个数组
handpose.on("predict", results => {
predictions = results;
});
video.hide();
}
function modelReady() {
console.log("Model ready!");
}
function draw() {
image(video, 0, 0, width, height);
drawKeypoints();
}
function drawKeypoints() {
for (let i = 0; i < predictions.length; i += 1) {
const prediction = predictions[i];
for (let j = 0; j < prediction.landmarks.length; j += 1) {
const keypoint = prediction.landmarks[j];
fill(0, 255, 0);
noStroke();
ellipse(keypoint[0], keypoint[1], 10, 10);
}
}
}