import processing.video.*;
Capture camera;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
image(camera, 0, 0);
}
void captureEvent(Capture camera){
camera.read();
}
カメラ映像を白黒にする
import processing.video.*;
Capture camera;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
camera.loadPixels();
loadPixels();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
color c = camera.pixels[y * width + x];
float grey = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
pixels[y * width + x] = color(grey, grey, grey);
}
}
updatePixels();
}
void captureEvent(Capture camera){
camera.read();
}
カメラ映像を2値化する
import processing.video.*;
Capture camera;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
camera.loadPixels();
loadPixels();
for(int x = 0; x < width; x += 1){
for(int y = 0; y < height; y += 1){
color c = camera.pixels[y * width + x];
float grey = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
if(grey > (float(mouseY) / height) * 255){
pixels[y * width + x] = color(255);
} else {
pixels[y * width + x] = color(0);
}
}
}
updatePixels();
}
void captureEvent(Capture camera){
camera.read();
}
カメラ映像の色を反転する
import processing.video.*;
Capture camera;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
camera.loadPixels();
loadPixels();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
color c = camera.pixels[y * width + x];
pixels[y * width + x] = color(255 - red(c), 255 - green(c), 255 - blue(c));
}
}
updatePixels();
}
void captureEvent(Capture camera){
camera.read();
}
空間微分する(輪郭を抽出する)
import processing.video.*;
Capture camera;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
}
void draw(){
camera.loadPixels();
loadPixels();
color[][] greys = new color[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
color c = camera.pixels[y * width + x];
float grey = 0.30 * red(c) + 0.59 * green(c) + 0.11 * blue(c);
greys[x][y] = color(grey, grey, grey);
}
}
for(int x = 0; x < width ; x += 1){
for(int y = 0; y < height; y += 1){
if(x == 0 || x == width - 1 || y == 0 || y == height - 1){
pixels[y * width + x] = color(0);
} else {
float vg = - red(greys[x - 1][y - 1]) +
- 2 * red(greys[x - 1][y]) +
- red(greys[x - 1][y + 1]) +
red(greys[x + 1][y - 1]) +
2 * red(greys[x + 1][y]) +
red(greys[x + 1][y + 1]);
float hg = - red(greys[x - 1][y - 1]) +
- 2 * red(greys[x][y - 1]) +
- red(greys[x + 1][y - 1]) +
red(greys[x - 1][y + 1]) +
2 * red(greys[x][y + 1]) +
red(greys[x + 1][y + 1]);
float grey = sqrt(sq(vg) + sq(hg));
pixels[y * width + x] = color(grey, grey, grey);
}
}
}
updatePixels();
}
void captureEvent(Capture camera){
camera.read();
}
時間微分する(動きを抽出する)
import processing.video.*;
Capture camera;
color[][] previousPixels;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
previousPixels = new color[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
previousPixels[x][y] = 127;
}
}
}
void draw(){
camera.loadPixels();
loadPixels();
color[][] currentPixels = new color[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
currentPixels[x][y] = camera.pixels[y * width + x];
}
}
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
float r = abs(red(previousPixels[x][y]) - red(currentPixels[x][y]));
float g = abs(green(previousPixels[x][y]) - green(currentPixels[x][y]));
float b = abs(blue(previousPixels[x][y]) - blue(currentPixels[x][y]));
pixels[y * width + x] = color(r, g, b);
}
}
updatePixels();
previousPixels = currentPixels;
}
void captureEvent(Capture camera){
camera.read();
}