-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
56 lines (43 loc) · 968 Bytes
/
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
let video;
let label = "waiting...";
let classifier;
let modelURL = 'https://teachablemachine.withgoogle.com/models/MioAyAlS/';
function preload() {
classifier = ml5.imageClassifier(modelURL + 'model.json');
}
function setup() {
createCanvas(900, 520);
video = createCapture(VIDEO);
video.hide();
classifyVideo();
}
function classifyVideo() {
classifier.classify(video, gotResults);
}
function draw() {
background(0);
image(video, 0, 0);
textSize(32);
textAlign(CENTER, CENTER);
fill(255);
text(label, width / 2, height - 16);
let emoji = "📱";
if (label == "HUMAN") {
emoji = "🙋♂️";
} else if (label == "BALL") {
emoji = "🥎";
} else if (label == "BOTTLE") {
emoji = "🍾";
}
textSize(225);
text(emoji, 780, 200);
}
function gotResults(error, results) {
if (error) {
console.error(error);
return;
}
label = results[0].label;
//console.log(results);
classifyVideo();
}