-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
62 lines (45 loc) · 1.1 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
var video;
var classifier;
var label;
var confidence;
var coinSoundDetector;
function preload(){
classifier = ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/BjPsn2FXm/model.json');
coinSoundDetector = loadSound('sound/metaldetector1.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(10);
label = 'Aguarde...';
video = createCapture(VIDEO);
video.hide();
classifyVideo();
}
function classifyVideo(){
classifier.classify(video, gotResults);
}
function draw() {
classifyVideo();
background(0);
image(video, 0, 0, width, height - 45);
textSize(20);
textAlign(CENTER, CENTER);
fill(255);
text(label, width / 2, height - 25);
}
function gotResults(error, results){
if(error){
console.log(error);
return;
}
confidence = results[0].confidence;
if(confidence == 1){
label = results[0].label;
coinSoundDetector.play();
}else{
label = "Não Identificado";
}
//console.log(results[0].label);
//console.log(results[0].confidence);
//console.log(results);
}