-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
57 lines (48 loc) · 1.47 KB
/
main.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
img = "";
objects = [];
status = "";
function preload(){
img = loadImage('dog_cat.jpg');
}
function setup() {
canvas = createCanvas(380, 380);
canvas.center();
video = createCapture(VIDEO);
video.hide();
objectDetector = ml5.objectDetector('cocossd', modelLoaded);
document.getElementById("status").innerHTML = "Status : Detecting Objects";
}
function modelLoaded() {
console.log("Model Loaded!");
status = true;
objectDetector.detect(video, gotResult);
}
function gotResult(error, results) {
if (error) {
console.log(error);
}
console.log(results);
objects = results;
}
function draw() {
image(video, 0, 0, 380, 380);
if(status != "")
{
r = random(255);
g = random(255);
b = random(255);
objectDetector.detect(video, gotResult);
for (i = 0; i < objects.length; i++) {
document.getElementById("status").innerHTML = "Status : Object Detected";
document.getElementById("number_of_objects").innerHTML = "Number of Objects Detected are : " + objects.length;
//fill("#FF0000");
fill(r,g,b);
percent = floor(objects[i].confidence * 100);
text(objects[i].label + " " + percent + "%", objects[i].x + 15, objects[i].y + 15);
noFill();
//stroke("#FF0000");
stroke(r,g,b);
rect(objects[i].x, objects[i].y, objects[i].width, objects[i].height);
}
}
}