-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
72 lines (62 loc) · 2.26 KB
/
Copy pathindex.html
File metadata and controls
72 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<meta charset="UTF-8" />
<title>Handpose with Webcam</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://unpkg.com/ml5@0.6.1/dist/ml5.min.js" type="text/javascript"></script>
<script src="three.js"></script>
<style>
body { margin: 0; }
</style>
</head>
<body>
<h1>Handpose with Webcam</h1>
<video id="video" autoplay playinline muted></video>
<canvas id="bg"></canvas>
<script>
let handpose;
let predictions = [];
const video = document.querySelector("#video")
const init = async () => {
const stream = await navigator.mediaDevices.getUserMedia({video:true})
video.srcObject = stream;
}
handpose = ml5.handpose(video, modelReady);
function modelReady() {
console.log("Model ready!");
}
handpose = ml5.handpose(video, modelReady);
// This sets up an event that fills the global variable "predictions"
// with an array every time new hand poses are detected
handpose.on("predict", results => {
predictions = results;
});
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer({
canvas: document.querySelector("#bg")
});
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize( window.innerWidth, window.innerHeight );
camera.position.setZ(30)
renderer.render( scene, camera)
const geometry = new THREE.BoxGeometry(1,1,1)
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00, wireframe: true } );
const cube1 = new THREE.Mesh( geometry, material );
const cube2 = new THREE.Mesh( geometry, material );
cube2.position.x = 2
cube2.position.y = 2
cube2.position.z = 2
scene.add( cube1, cube2 );
const animate = () => {
requestAnimationFrame(animate)
renderer.render(scene, camera)
console.log(predictions)
}
animate()
init()
camera.position.z = 5;
</script>
</body>
</html>