We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Background difference -> vertex points
Page Index Toggle Pages: 1
Background difference -> vertex points? (Read 480 times)
Background difference -> vertex points?
Apr 20th, 2009, 1:32pm
 
Hi. I've got this fun-looking background difference thing going on (code below). It looks cool, but isn't quite what I want, which is something more like a vertex-based shape that I can then alter and mess with as I choose. I know reading through the single-dim pixels array, and running a brightness test on that pixel, turning it into a vertex if it passes, etc. doesn't do it (obviously a for() loop won't read the array in the correct direction for this to work properly). So, anyone have any ideas? I'm trying to take the moving shape it's detecting and be able to control it as a shape.

Code:
import hypermedia.video.*;
OpenCV opencv;
int numPixels;
int blackval;

void setup() {
size(320,240);
opencv=new OpenCV(this);
opencv.capture(width,height);
numPixels=opencv.width*opencv.height;
colorMode(HSB,100);
}

void draw() {
background(0);
opencv.read();
points();
}

void points() {
opencv.absDiff();
opencv.blur(OpenCV.BLUR,5);

int[] cap=opencv.pixels();
loadPixels();

for(int i=0; i<numPixels; i++) {
if(brightness(cap[i])>7) {
cap[i]=color(0,0,100);

}
}
updatePixels();

PImage newcap = createImage(width,height,HSB);
newcap.loadPixels();
for (int i = 0; i < numPixels; i++) {
newcap.pixels[i] = cap[i];
}
newcap.updatePixels();
image(newcap,0,0);

filter(INVERT);
opencv.remember();
}
Page Index Toggle Pages: 1