-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain1.js
71 lines (61 loc) · 1.47 KB
/
main1.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
img = "";
status = "";
objects = [];
function preload()
{
img = loadImage('dog_cat.jpg');
}
function setup()
{
canvas = createCanvas(640,420);
canvas.center();
objectDetector = ml5.objectDetector('cocossd',modelLoaded);
document.getElementById("status").innerHTML = "Status : detecting objects";
}
function modelLoaded()
{
console.log("model Loaded");
status = true;
window.alert(status);
objectDetector.detect(img, gotResult);
}
function gotResults(error,results)
{
if(error)
{
console.log(error);
}
else
{
console.log(results);
objects = results;
}
}
function draw()
{
/*image(img,0,0,640,420);
fill("#FF0000");
text("Dog",45,75);
noFill();
stroke("#FF0000");
rect(30,60,450,350);
fill("#FF0000");
text("Cat",320,120);
noFill();
stroke("#FF0000");
rect(300,90,270,320)*/
image(img,0,0,640,420);
if(status != "")
{
for(i=0; i<objects.length; i++)
{
document.getElementById("status").innerHTML = "Status : object detected";
fill("#FF0000");
percent = floor(objects[i].confidence * 100);
text(objects[i].label + " " + percent + "%", objects[i].x, objects[i].y);
noFill();
stroke("#FF0000");
rect( objects[i].x, objects[i].y, objects[i].width, objects[i].height);
}
}
}