i am very new to processing and trying to archieve following task where i am using kinect camera and openkinect library by shiffman, I have designed the grid (8 colums and 6 rows for ex) based to movement in front of cam the grid shows the colored rectagle. the perticular grid shows the movement is happening in perticular grid. In my problem in place of rectagle filled with color i want portion of another image to get more visible on the movement grid. please help me.. :-)
following is the code I am using for for project
import processing.opengl.*;
import org.openkinect.*;
import org.openkinect.processing.*;
Kinect kinect;
int kAngle = 0;
final int VIDEO_WIDTH = 640;
final int VIDEO_HEIGHT = 480;
// Anzahl der Quadranten in der Breite
final int VIDEO_COLS = 8;
// Anzahl der Quadranten in der Höhe
final int VIDEO_ROWS = 6;
/*PImage prevImage;
PImage presentImage;
int threshold = 20;
int offset; */
float[] activity = new float[VIDEO_COLS * VIDEO_ROWS];
float[] buffer1 = new float[VIDEO_WIDTH * VIDEO_HEIGHT];
float[] buffer2 = new float[buffer1.length];
float[] buffer3 = new float[buffer1.length];
PImage bldg;
PImage myImg;
int index;
int val=255;
void setup()
{
size(640, 480, OPENGL);
frameRate(30);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
kinect.enableRGB(true);
kinect.tilt(kAngle);
tint(255, val);
bldg = loadImage("building.jpg");
// myImg = loadImage("denmark.jpg");
}
void draw()
{
background(0);
// tint(255,0);
image(bldg,0,0);
if (true) {
int pxPerCol = VIDEO_WIDTH / VIDEO_COLS;
int pxPerRow = VIDEO_HEIGHT / VIDEO_ROWS;
PImage img = kinect.getVideoImage();
// image(img, 0,0);
// 'activity' array auf 0 setzen
for (int i=0; i < activity.length; i++) {
activity[i] = 0;
}
for (int i=0; i < img.pixels.length; i++) {
int x = (int) ((i % img.width) / pxPerCol);
int y = (int) ((i / img.width) / pxPerRow);
index = y * VIDEO_COLS + x;
color col = img.pixels[i];
float sum = red (col) + green (col) + blue (col);
float deltaPixel = (buffer1[i] + buffer2[i] + buffer3[i]) / 3 - sum;
if (deltaPixel < 0) {
deltaPixel *= -1;
}
activity[index] += deltaPixel;
buffer3[i] = buffer2[i];
buffer2[i] = buffer1[i];
buffer1[i] = sum;
}
for (int i=0; i < activity.length; i++) {
activity[i] /= pxPerCol* pxPerRow;
// PImage cimg = get((i % VIDEO_COLS) * pxPerCol, (i / VIDEO_COLS) * pxPerRow, pxPerCol, pxPerRow);
// tint(255, 255);
// image(cimg, (i % VIDEO_COLS) * pxPerCol, (i / VIDEO_COLS) * pxPerRow);
val = 255;
// fill(0, 10);
// rect(0, 0, width, height);
stroke (255, 20);
fill (0, 255, 230, activity[i]);
//ambientLight(255, 255, 255);
//fill(200, activity[i]);
rect((i % VIDEO_COLS) * pxPerCol, (i / VIDEO_COLS) * pxPerRow, pxPerCol, pxPerRow);
}
}
fill(255);
text("TILT: " + kAngle, 10, 20);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
kAngle+=15;
}
else if (keyCode == DOWN) {
kAngle-=15;
}
kAngle = constrain(kAngle, 0, 30);
kinect.tilt(kAngle);
}
}
void quit() {
kinect.quit();
super.stop();
}
1