-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
92 lines (78 loc) · 2.05 KB
/
sketch.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// HOW TO USE
// predictWebcam(video) will start predicting landmarks
// pass a video MediaElement using createCapture
// make sure to call predictWebcam as a callback to createCapture
// this ensures the video is ready
// parts index:
// https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/index
let capture;
let loadedCamera;
let captureEvent;
let confidence = 0.0;
let yOff = 0;
let defaultWeight = 50;
let lerpRate = 0.4;
let madeClone = false;
let lerpLandmarks = [];
function setup() {
createCanvas(windowWidth, windowHeight);
captureWebcam();
}
function draw() {
// background(255);
image(capture, 0, 0);
fill(255,240)
noStroke()
rect(0,0,width, height)
// console.log({landmarks})
let first = true;
if (landmarks.length > 0) {
for (const hand of landmarks) {
first ? fill(255,0,0) : fill(0,255,0)
first = false;
for(const m of hand){
circle(m.x * capture.width, m.y * capture.height, m.z * 100);
}
}
}
}
function captureWebcam() {
capture = createCapture(
{
audio: false,
video: {
facingMode: "user",
},
},
function (e) {
captureEvent = e;
// do things when video ready
// until then, the video element will have no dimensions, or default 640x480
capture.srcObject = e;
setCameraDimensions();
predictWebcam(capture);
}
);
capture.elt.setAttribute("playsinline", "");
capture.hide();
}
function setCameraDimensions() {
loadedCamera = captureEvent.getTracks()[0].getSettings();
// console.log("cameraDimensions", loadedCamera);
if (capture.width > capture.height) {
capture.size(width, (capture.height / capture.width) * width);
} else {
capture.size((capture.width / capture.height) * height, height);
}
// console.log(capture);
}
function getAngle(v0x, v0y, v1x, v1y) {
return atan2(v1y - v0y, v1x - v0x);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
setCameraDimensions();
}
function simpLerp(a, b, rate) {
return a + rate * (b - a);
}