-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathyolo-v1.js
More file actions
62 lines (50 loc) · 1.24 KB
/
yolo-v1.js
File metadata and controls
62 lines (50 loc) · 1.24 KB
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
/* reference/image/YOLO Object Detection v1
*
* */
let video;
let yolo;
let status;
let objects = [];
let canvasWidth = 640;
let canvasHeight = 480;
function setup() {
frameRate(1); // per sec trigger of draw
createCanvas(canvasWidth, canvasHeight);
video = createCapture(VIDEO);
video.size(canvasWidth, canvasHeight);
yolo = ml5.YOLO(video, triggerDetect);
video.hide();
status = select("#status");
}
function triggerDetect() {
console.log("+ detecting...")
yolo.detect(function(err, results){
if (err) {
console.error(err);
return;
}
objects = results;
triggerDetect();
});
}
function draw() {
let width = canvasWidth - 10;
let height = canvasHeight - 10;
image(video, 5, 5, width, height);
if (!yolo.modelReady) {
console.log('model not loaded yet');
return;
}
for (let i = 0; i < objects.length; i++) {
let an_object = objects[i];
let label = an_object.label + "(" + an_object.confidence + ")";
status.html(label);
noStroke();
fill(0, 0, 255);
text(label, an_object.x * width, an_object.y * height);
noFill();
strokeWeight(4);
stroke(0, 0, 255);
rect(an_object.x * width, an_object.y * height, an_object.w * width, an_object.h * height);
}
}