-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetection.js
36 lines (33 loc) · 988 Bytes
/
detection.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
let img;
let detector;
//img.crossOrigin='Anonymous';
function preload(){
img=loadImage('img/puffin.jpg');
detector=ml5.objectDetector('cocossd');
}
function gotdetections(error,results){
if(error){console.error(error);}
console.log(results);
for(let i=0;i<results.length;i++){
let ob=results[i];
let xnorm=ob.normalized.x*width;
let ynorm=ob.normalized.y*height;
let wnorm=ob.normalized.width*width;
let hnorm=ob.normalized.height*height;
stroke(0,255,0);
strokeWeight(4);
noFill();
rect(xnorm,ynorm,wnorm,hnorm);
noStroke();
fill(255);
textSize(24);
text(ob.label+', with '+(ob.confidence*100).toFixed(2)+'% confidence',xnorm+10,ynorm+24);
}
}
function setup(){
createCanvas(640,480);
//canvas.parent('content');
image(img,0,0,width,height);
detector.detect(img,gotdetections);
document.getElementById('content').appendChild(canvas);
}