Kinect Visualization Sporadic in Function (Getting Runtime Exception Errors)

edited February 2014 in Kinect

For some reason the Kinect visualization for my sketch is now getting this error:

java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 5 (along with a mess of other errors)

But the strange thing is, it was working fine before. I've made no changes to the code so I don't know what the problem is. Solutions?

import SimpleOpenNI.*;
import processing.serial.*;

Serial myPort;

SimpleOpenNI context;
float        zoomF =0.3f;
float        rotX = radians(180);  // by default rotate the hole scene 180deg around the x-axis, 
                                   // the data from openni comes upside down
float        rotY = radians(0);

int cO2Val; // CO2 Value
int vis; // Visualization value
int trans = 150;
String s;

void setup()
{
  size(displayWidth, displayHeight, P3D);

  context = new SimpleOpenNI(this);
  if(context.isInit() == false)
  {
     println("Can't init SimpleOpenNI, maybe the camera is not connected!"); 
     exit();
     return;  
  }

  // disable mirror
  context.setMirror(false);

  // enable depthMap generation 
  context.enableDepth();

  stroke(255,255,255);
  smooth();
  perspective(radians(45),
              float(width)/float(height),
              10,150000);
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
  println("End of setup()");            
}


void draw()
{
  println("In draw()");
  // update the cam
  context.update();

  s = myPort.readStringUntil(':');
  if (s != null) {
    cO2Val = Integer.parseInt(s.substring(0, s.length() - 1));
    vis = cO2Val / 100; // Reduce value for visualization

  }
  println(map(cO2Val,500,5000,0,255));
  println("circle size = " + vis);

  background(0, 0, 0);

  translate(width/2, height/2, 0);
  rotateX(rotX);
  rotateY(rotY);
  scale(zoomF);

  int[]   depthMap = context.depthMap();
  int     steps   = 3;  // to speed up the drawing, draw every third point
  int     index;
  PVector realWorldPoint;

  translate(0,0,-1000);  // set the rotation center of the scene 1000 infront of the camera

  //stroke(map(cO2Val,500,5000,0,255));
  //fill(map(cO2Val,500,5000,0,255));
  stroke(0, 0, 0);

  PVector[] realWorldMap = context.depthMapRealWorld();

  // draw pointcloud
  beginShape(POINTS);
  println("Drawing points");
  for(int y=0;y < context.depthHeight();y+=steps)
  {
    for(int x=0;x < context.depthWidth();x+=steps)
    {
      index = x + y * context.depthWidth();
      if(depthMap[index] > 0)
      { 
        // draw the projected point
        realWorldPoint = realWorldMap[index];
        vertex(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);
        fill(255, 255, 255, trans);
        ellipse(realWorldPoint.x, realWorldPoint.y, vis, vis);

      }
    }
  } 
  endShape();

  // draw the kinect cam
  //context.drawCamFrustum();
}
Tagged:

Answers

Sign In or Register to comment.