-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_200421a.pde
83 lines (73 loc) · 1.85 KB
/
sketch_200421a.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import processing.video.*;
Capture cam;
PImage img,imgatt;
PImage viewer;
int cols, rows; // Number of columns and rows in our system
int noff=-120;
int poff=30;
void setup()
{
size(640, 420, P2D);
cols = width;
rows = height;
img = createImage(width, height, RGB);
imgatt = createImage(width, height, RGB);
viewer = createImage(width, height, RGB);
String[] cameras = Capture.list();
if (cameras.length!= 0){
cam = new Capture(this, cameras[1]);
cam.start();
}
}
void keyPressed() {
copyn();
}
void copyn(){
img.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height);
img.updatePixels();
}
boolean once=true;
void draw()
{
if(once){
once=false;
copyn();
}
if (cam.available() == true){
imgatt.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height);
imgatt.updatePixels();
viewer.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height);
viewer.updatePixels();
cam.read();
}
loadPixels();
cam.loadPixels();
imgatt.loadPixels();
img.loadPixels();
viewer.loadPixels();
for ( int x = 0; x < cols;x+=1) {
for ( int y = 0; y < rows;y+=1) {
int loc = (x + y*cols);
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
float r2 = red(imgatt.pixels[loc]);
float g2 = green(imgatt.pixels[loc]);
float b2 = blue(imgatt.pixels[loc]);
if(numberAround(int(r)-int(r2),int(noff),int(poff))&&numberAround(int(b)-int(b2),int(noff),int(poff))&&numberAround(int(g)-int(g2),int(noff),int(poff))){
viewer.pixels[loc]=color(0,255,0);
} else{
viewer.pixels[loc]=imgatt.pixels[loc];
}
}
}
viewer.updatePixels();
image(viewer, 0, 0);
}
boolean numberAround(int a,int b,int c){
boolean tot=false;
if(a>b&&a<c){
tot=true;
}
return tot;
}