-
Notifications
You must be signed in to change notification settings - Fork 14
/
ControlThresholdFilter.pde
55 lines (39 loc) · 1.19 KB
/
ControlThresholdFilter.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
import ch.bildspur.realsense.*;
import ch.bildspur.realsense.type.*;
import ch.bildspur.realsense.processing.*;
RealSenseCamera camera = new RealSenseCamera(this);
RSThresholdFilter thresholdFilter;
float minDistance = 0.0f;
float maxDistance = 4.0f;
float size = 0.5f;
boolean filterOn = false;
void setup()
{
size(1280, 720, FX2D);
// enable depth stream
camera.enableDepthStream(1280, 720);
// enable colorizer to display depth
camera.enableColorizer(ColorScheme.Warm);
// add threshold filter
thresholdFilter = camera.addThresholdFilter();
camera.start();
}
void draw()
{
background(0);
// adjust filter
float filterCenter = map(mouseX, 0, height, minDistance, maxDistance);
if (filterOn) {
thresholdFilter.setMinDistance(constrain(filterCenter - (size * 0.5f), minDistance, maxDistance - size));
thresholdFilter.setMaxDistance(constrain(filterCenter + (size * 0.5f), minDistance + size, maxDistance));
}
// read frames
camera.readFrames();
// show color image
image(camera.getDepthImage(), 0, 0, width, height);
}
void keyPressed() {
thresholdFilter.setMinDistance(minDistance);
thresholdFilter.setMaxDistance(maxDistance);
filterOn = !filterOn;
}