-
Notifications
You must be signed in to change notification settings - Fork 22
/
YOLOWebcamExample.pde
67 lines (47 loc) · 1.46 KB
/
YOLOWebcamExample.pde
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
import ch.bildspur.vision.*;
import ch.bildspur.vision.result.*;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PImage;
import processing.video.Capture;
Capture cam;
DeepVision deepVision = new DeepVision(this);
YOLONetwork yolo;
ResultList<ObjectDetectionResult> detections;
int textSize = 12;
public void setup() {
size(640, 480);
colorMode(HSB, 360, 100, 100);
println("creating model...");
yolo = deepVision.createYOLOv4Tiny();
println("loading yolo model...");
yolo.setup();
cam = new Capture(this, "pipeline:autovideosrc");
cam.start();
}
public void draw() {
background(55);
if (cam.available()) {
cam.read();
}
image(cam, 0, 0);
if (cam.width == 0) {
return;
}
yolo.setConfidenceThreshold(0.2f);
detections = yolo.run(cam);
strokeWeight(3f);
textSize(textSize);
for (ObjectDetectionResult detection : detections) {
int hue = (int)(360.0 / yolo.getLabels().size() * detection.getClassId());
noFill();
stroke(hue, 80, 100);
rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight());
fill(hue, 80, 100);
rect(detection.getX(), detection.getY() - (textSize + 3), textWidth(detection.getClassName()) + 4, textSize + 3);
fill(0);
textAlign(LEFT, TOP);
text(detection.getClassName(), detection.getX() + 2, detection.getY() - textSize - 3);
}
surface.setTitle("Webcam YOLO Test - FPS: " + Math.round(frameRate));
}