For this weeks Computational Cameras assignment, I attempted to do edge detection. I looked at trying to combine the example code for doing pixel by pixel in video set out by Dan O’Sullivan here in tracking the single pixel / tracking a difference in color. I then attempted to use what is on the processing.org website for edge detection, but ended up with some rather strange results.
(Video is pending):

Here is the code (both of these results came from messing around with the initial kernel, though in the second one I maintained the information for all 3 colors rather than converting to grayscale). Oh yeah, and before I forget to mention it, Eclipse is super annoying
import processing.core.PApplet;
import processing.video.Capture;
public class n extends PApplet {
Capture video;// regular processing library
int threshold = 250; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR = 0;
float objectG = 0;
float objectB = 0;
boolean debug = true;
public void setup() {
size(640, 480);
println(Capture.list());
video = new Capture(this,width,height);
//video.settings();
}
public void draw(){
if (video.available()){
video.read();
//enter into the classic nested for statements of computer vision
for (int row = 1; row < video.height-1; row++) {
for (int col = 1; col < video.width-1; 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 * width + col;
//pull out the same pixel from the current frame
int thisColor = video.pixels[offset];
int lastColor = video.pixels[offset-1];
//pull out the individual colors for both pixels
float r = red(thisColor);
float g = green(thisColor);
float b = blue(thisColor);
lastColor = row*width + col -1;
objectR = red(lastColor);
objectG = green(lastColor);
objectB = blue(lastColor);
//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
video.pixels[offset-1] = color(255);
}
}
}
}
image(video, 0, 0);
}
public void keyPressed() {
//for adjusting things on the fly
if (key == 's') {
video.settings();
}
}
}
Pingback: Week 3:Pixel by Pixel « Comperas