kinect image processing eating too much memory
in
Integration and Hardware
•
11 months ago
Hi,
I'm trying to create a program that recognizes electric blue color at a particular depth. For this I'm using a kinect and SimpleOpenNI library in Processing 2.0b5. When I try to display the image created after filtering the colors I don't want, the pixels too far and the ones too close from my 'depth of interest', the program complains about running out of memory soon after it started.
I'd appreciate some advice of what I could I change to avoid the memory problem (I already tried increasing the limit in the IDE preferences window to 1 GB but it was unsuccessful).
The code:
- import SimpleOpenNI.*;
- SimpleOpenNI kinect;
- int closestValue;
- int closestX;
- int closestY;
- int minRange = 600;
- int maxRange= 1400;
- PImage ttoolCursor;
- PImage ttoolDrawing;
- float lastX;
- float lastY;
- void setup()
- {
- size(640, 480);
- colorMode(HSB, 359);
- kinect = new SimpleOpenNI(this);
- kinect.enableDepth();
- kinect.enableRGB();
- kinect.alternativeViewPointDepthToImage();
- ttoolCursor = loadImage("pde-16.png");
- ttoolDrawing = createImage(640, 480, RGB);
- stroke(245, 359, 359);
- fill(245, 359, 359);
- strokeWeight(3);
- background(0);
- }
- void draw()
- {
- background(0);
- closestValue = 8000;
- kinect.update();
- PImage rgbImage = kinect.rgbImage();
- PImage rgbImageMirror = createImage(640, 480, RGB);
- int[] depthValues = kinect.depthMap();
- rgbImage.loadPixels();
- for (int i = 0; i < rgbImage.pixels.length; i++) {
- if (depthValues[i] <= minRange || depthValues[i] >= maxRange) {
- rgbImage.pixels[i] = color(0, 0, 0);
- }
- else if (hue(rgbImage.pixels[i]) <= 200 || hue(rgbImage.pixels[i]) >=260 || hue(rgbImage.pixels[i]) <=215 || brightness(rgbImage.pixels[i]) <=215) {
- rgbImage.pixels[i] = color(0, 0, 0);
- }
- }
- rgbImage.updatePixels();
- rgbImageMirror.loadPixels();
- for (int y = 0; y < 480; y++) {
- for (int x = 0; x < 640; x++) {
- int reversedX = 640-x-1;
- int i = reversedX + y * 640;
- int j = x + y * 640;
- rgbImageMirror.pixels[j] = rgbImage.pixels[i];
- }
- }
- rgbImageMirror.updatePixels();
- //float interpolatedX = lerp(lastX, closestX, 0.3f);
- //float interpolatedY = lerp(lastY, closestY, 0.3f);
- image(rgbImageMirror, 0, 0);
- //image(ttoolCursor, interpolatedX, interpolatedY);
- //lastX = interpolatedX;
- //lastY = interpolatedY;
- println(frameRate);
- }
1