If white pixel falls within ellipse bounds cause a hit.
in
Contributed Library Questions
•
4 months ago
Hi Everyone,
I am trying to perform a hit test using white pixels but not too sure how to do it;
I have some code i modified to suit my needs that gives me black and white pixels for different depths (using a kinect)
So my question is;
if i have an ellipse in the image and a white pixel occupy the same space how can i make something happen to the ellipse (maybe change colour);
I thought get(); might do it but doesn't seem to work?
If somebody could point me in the right direction Id appreciate it!
Regards,
Oli
Heres the code for the black and white depth image;
import hypermedia.video.*;
import java.awt.Rectangle;
import java.awt.Point;
import SimpleOpenNI.*;
PImage display;
SimpleOpenNI context;
OpenCV opencv;
PFont font;
void setup() {
context = new SimpleOpenNI(this);
// mirror is by default enabled
context.setMirror(true);
// enable depthMap generation
if (context.enableDepth() == false)
{
println("Can't open the depthMap, maybe the camera is not connected!");
exit();
return;
}
size(640, 480);
opencv = new OpenCV( this );
opencv.capture(640, 480);
font = loadFont( "AndaleMono.vlw" );
textFont( font );
println( "Drag mouse inside sketch window to change threshold" );
println( "Press space bar to record background image" );
}
void draw() {
//get the information from the kinext
context.update();
//convert to img (to avoid nullpointerexception)
display = context.depthImage();
display.loadPixels();
//loop to select a depthzone
for (int x = 0; x < context.depthWidth(); x++) {
for (int y = 0; y < context.depthHeight(); y++) {
// mirroring image
int offset =context.depthWidth()-x-1+y*context.depthWidth();
int[] depthValues = context.depthMap();
int rawDepth = depthValues[offset];
int pix = x + y *context.depthWidth();
//only get the pixel corresponding to a certain depth
int depthmin=300;
int depthmax=1500;
if (rawDepth <depthmax && rawDepth > depthmin) {
// A red color instead
display.pixels[pix] = color(255);
} else {
display.pixels[pix] = color(0);
}
}
}
display.updatePixels();
background(0);
//resize and copy to opencv object
opencv.copy(display, 0, 0, context.depthWidth(), context.depthHeight(), 0, 0, 640, 480);
image( opencv.image(OpenCV.GRAY), 0, 0 );
}
1