processing
import processing.video.*;
import processing.serial.*;
Capture camera;
Serial myPort;
void setup() {
size(480, 320);
myPort = new Serial(this,Serial.list()[1],9600);
camera = new Capture(this, width, height, Capture.list()[2], 12);
smooth();
noStroke();
}
void draw() {
background(0);
noStroke();
camera.loadPixels(); //カメラ画像のpixel情報を読み込み
int d = 1; //円の直径を定義
// ライブカメラの映像から、円の直径の間隔ごとに、色情報を取得し、その色で円を描く
for(int y = d / 2 ; y < height ; y += d) {
for(int x = d / 2 ; x < width ; x += d) {
fill(camera.pixels[y * width + x]);
ellipse(x, y, d, d);
}
}
text(
"X="+mouseX + " " +
"Y="+mouseY + " " +
"R="+red(camera.pixels[mouseY * width + mouseX]) + " " +
"G="+green(camera.pixels[mouseY * width + mouseX]) + " " +
"B="+blue(camera.pixels[mouseY * width + mouseX]) + " "
,10
,20
);
stroke(256,0,0);
strokeWeight(3);
noFill();
ellipse(mouseX, mouseY, 20, 20);
if(
red(camera.pixels[mouseY * width + mouseX]) < 20 &&
green(camera.pixels[mouseY * width + mouseX]) < 20 &&
blue(camera.pixels[mouseY * width + mouseX]) < 20
){
myPort.write(1);
}else{
myPort.write(0);
}
}
void captureEvent(Capture camera) {
camera.read();
}
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
if(Serial.available()>0){
if(Serial.read()==1){
digitalWrite(13, HIGH);
}else{
digitalWrite(13, LOW);
}
}
}