-
Notifications
You must be signed in to change notification settings - Fork 0
/
scr.js
57 lines (54 loc) · 1.6 KB
/
scr.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
function openCam(){
let mdev=navigator.mediaDevices
if (!mdev || !mdev.getUserMedia) {
console.log("getUserMedia() not supported.");
return;
}
mdev.getUserMedia({
video: true
})
.then(function(vidStream) {
var video = document.getElementById('videoCam');
if ("srcObject" in video) {
video.srcObject = vidStream;
} else {
video.src = window.URL.createObjectURL(vidStream);
}
video.onloadedmetadata = function(e) {
video.play();
};
})
.catch(function(e) {
console.log(e.name + ": " + e.message);
});
}
function modelLoaded() {
console.log('Model Loaded!');
}
function trainModel(){
let paragraph = document.getElementById("paragraph");
selectElement = document.querySelector('#model_opt');
model_value = selectElement.value;
if(model_value=='MobileNet'){
const classifier = ml5.imageClassifier(model_value, modelLoaded);
classifier.classify(document.getElementById('videoCam'), (err, results) => {
let first=results[0];
paragraph.innerHTML=JSON.stringify(first);
}); }
else if(model_value=='SpeechCommands18w'){
const options = { probabilityThreshold: 0.7 };
const classifier = ml5.soundClassifier('SpeechCommands18w', options, modelReady);
function modelReady() {
// classify sound
classifier.classify(gotResult);
}
function gotResult(error, result) {
if (error) {
console.log(error);
return;
}
// log the result
console.log(result);
}
}
}