Code for pixel mapping
import processing.video.*;
Movie bird;
float xpos = 640; //used for the movement of the bird video
float ypos = 400;
Capture cam;// regular processing libary
int threshold = 10; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =206; //this is the set yellow of my highlighter
float objectG = 191;
float objectB = 98;
boolean debug = true;
void setup() {
size(640, 480);
println(Capture.list());
cam = new Capture(this, width, height);
cam.start();
bird = new Movie(this, "doveBW.mov");
bird.play();
}
void movieEvent(Movie bird) {
bird.read();
}
void draw() {
if (cam.available()) {
cam.read();
int totalFoundPixels= 0; //we are going to find the average location of change pixes so
int sumX = 0; //we will need the sum of all the x find, the sum of all the y find and the total finds
int sumY = 0;
//enter into the classic nested for statements of computer vision
for (int row = 0; row < cam.height; row++) {
for (int col = 0; col < cam.width; col++) {
//the pixels file into the room long line you use this simple formula to find what row and column the sit in
int offset = row * cam.width + col; //pull out the same pixel from the current frame
int thisColor = cam.pixels[offset];
float r = red(thisColor);//pull out the individual colors for both pixels
float g = green(thisColor);
float b = blue(thisColor);
//in a color "space" you find the distance between color the same whay you would in a cartesian space, phythag or dist in processing
float diff = dist(r, g, b, objectR, objectG, objectB);
if (diff < threshold) { //if it is close enough in size, add it to the average
sumX = sumX + col;
sumY= sumY + row;
totalFoundPixels++;
if (debug) cam.pixels[offset] = 0xff000000;//debugging
}
}
}
fill(0);
rect(0, 0, width, height);
if (totalFoundPixels > 1 ) {
aveX = sumX/totalFoundPixels;
aveY = sumY/totalFoundPixels;
background(0);
image(bird, xpos, ypos);
xpos = xpos-8;
ypos= ypos-5;
if (xpos < -240) {
xpos = 640;
bird.stop();
bird.play();
}
if (ypos<-150) {
ypos = 400;
bird.stop();
bird.play();
}
}
}
}
Movie bird;
float xpos = 640; //used for the movement of the bird video
float ypos = 400;
Capture cam;// regular processing libary
int threshold = 10; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =206; //this is the set yellow of my highlighter
float objectG = 191;
float objectB = 98;
boolean debug = true;
void setup() {
size(640, 480);
println(Capture.list());
cam = new Capture(this, width, height);
cam.start();
bird = new Movie(this, "doveBW.mov");
bird.play();
}
void movieEvent(Movie bird) {
bird.read();
}
void draw() {
if (cam.available()) {
cam.read();
int totalFoundPixels= 0; //we are going to find the average location of change pixes so
int sumX = 0; //we will need the sum of all the x find, the sum of all the y find and the total finds
int sumY = 0;
//enter into the classic nested for statements of computer vision
for (int row = 0; row < cam.height; row++) {
for (int col = 0; col < cam.width; col++) {
//the pixels file into the room long line you use this simple formula to find what row and column the sit in
int offset = row * cam.width + col; //pull out the same pixel from the current frame
int thisColor = cam.pixels[offset];
float r = red(thisColor);//pull out the individual colors for both pixels
float g = green(thisColor);
float b = blue(thisColor);
//in a color "space" you find the distance between color the same whay you would in a cartesian space, phythag or dist in processing
float diff = dist(r, g, b, objectR, objectG, objectB);
if (diff < threshold) { //if it is close enough in size, add it to the average
sumX = sumX + col;
sumY= sumY + row;
totalFoundPixels++;
if (debug) cam.pixels[offset] = 0xff000000;//debugging
}
}
}
fill(0);
rect(0, 0, width, height);
if (totalFoundPixels > 1 ) {
aveX = sumX/totalFoundPixels;
aveY = sumY/totalFoundPixels;
background(0);
image(bird, xpos, ypos);
xpos = xpos-8;
ypos= ypos-5;
if (xpos < -240) {
xpos = 640;
bird.stop();
bird.play();
}
if (ypos<-150) {
ypos = 400;
bird.stop();
bird.play();
}
}
}
}