-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
43 lines (34 loc) · 783 Bytes
/
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
let video;
let detector;
let detections = [];
function preload() {
detector = ml5.objectDetector('cocossd');
}
function gotDetections(error, results) {
if (error) {
console.error(error);
}
detections = results;
detector.detect(video, gotDetections);
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
detector.detect(video, gotDetections);
}
function draw() {
image(video, 0, 0);
for (let i = 0; i < detections.length; i++) {
let object = detections[i];
stroke(0, 255, 0);
strokeWeight(4);
noFill();
rect(object.x, object.y, object.width, object.height);
noStroke();
fill(0);
textSize(24);
text(object.label, object.x + 10, object.y + 24);
}
}