jp.nyatla.nyartoolkit.core.NyARException: java.lang.NullPointerException (AR tutorial Ammon Owed)

edited February 2014 in Library Questions

The code seems to want to function as the webcam on my Mac turns on but then the green light turns off and then I get the following error: jp.nyatla.nyartoolkit.core.NyARException: java.lang.NullPointerException. I've tried researching how to fix this problem but seemingly there is nothing. I am running processing 2.1.1 & have the latest .gsvideo & nyar4psg I have also included the whole stack trace below the code

import java.io.*; // for the loadPatternFilenames() function
import processing.opengl.*; // for OPENGL rendering
import jp.nyatla.nyar4psg.*; // the NyARToolkit Processing library
import codeanticode.gsvideo.*; // the GSVideo library

// a central location is used for the camera_para.dat and pattern files, so you don't have to copy them to each individual sketch
// Make sure to change both the camPara and the patternPath String to where the files are on YOUR computer
// the full path to the camera_para.dat file
String camPara = "/Users/Eddie/Documents/Processing/nyar4psg/data/camera_para.dat";
// the full path to the .patt pattern files
String patternPath = "/Users/Eddie/Documents/Processing/libraries/nyar4psg/patternMaker/examples/ARToolKit_Patterns";
// the dimensions at which the AR will take place. with the current library 1280x720 is about the highest possible resolution.
int arWidth = 640;
int arHeight = 360;
// the number of pattern markers (from the complete list of .patt files) that will be detected, here the first 10 from the list.
int numMarkers = 10;

// the resolution at which the mountains will be displayed
int resX = 60;
int resY = 60;
// this is a 2 dimensional float array that all the displayed mountains use during their update-to-draw routine
float[][] val = new float[resX][resY];

GSCapture cam;
MultiMarker nya;
float[] scaler = new float[numMarkers];
float[] noiseScale = new float[numMarkers];
float[] mountainHeight = new float[numMarkers];
float[] mountainGrowth = new float[numMarkers];

void setup() {
  size(1280, 720, OPENGL); // the sketch will resize correctly, so for example setting it to 1920 x 1080 will work as well
  cam = new GSCapture(this, 640, 480); // initializing the webcam capture at a specific resolution (correct/possible settings depends on YOUR webcam)
  cam.start(); // start capturing
  noStroke(); // turn off stroke for the rest of this sketch <span class="Emoticon Emoticon1"><span>:-)</span></span>
  // create a new MultiMarker at a specific resolution (arWidth x arHeight), with the default camera calibration and coordinate system
  nya = new MultiMarker(this, arWidth, arHeight, camPara, NyAR4PsgConfig.CONFIG_DEFAULT);
  // set the delay after which a lost marker is no longer displayed. by default set to something higher, but here manually set to immediate.
  nya.setLostDelay(1);
  String[] patterns = loadPatternFilenames(patternPath);
  // for the selected number of markers, add the marker for detection
  // create an individual scale, noiseScale and maximum mountainHeight for that marker (= mountain)
  for (int i=0; i<numMarkers; i++) {
    nya.addARMarker(patternPath + "/" + patterns[i], 80);
    scaler[i] = random(0.8, 1.9); // scaled a little smaller or bigger
    noiseScale[i] = random(0.02, 0.075); // the perlin noise scale to make it look nicely mountainy
    mountainHeight[i] = random(75, 150); // the maximum height of a mountain
  }
}

void draw() {
  // if there is a cam image coming in...
  if (cam.available()) {
    cam.read(); // read the cam image
    background(0); // a background call is needed for correct display of the marker results
    image(cam, 0, 0, width, height); // display the image at the width and height of the sketch window
    // create a copy of the cam image at the resolution of the AR detection (otherwise nya.detect will throw an assertion error!)
    PImage cSmall = cam.get();
    cSmall.resize(arWidth, arHeight);
    nya.detect(cSmall); // detect markers in the image
    drawMountains(); // draw dynamically flowing mountains on the detected markers (3D)
  }
}

// this function draws correctly placed 3D 'mountains' on top of detected markers
// while the mountains are displayed they grow (up to a certain point), while not displayed they return to the zero-state
void drawMountains() {
  // set the AR perspective uniformly, this general point-of-view is the same for all markers
  nya.setARPerspective();
  // turn on some general lights (without lights it also looks pretty cool, try commenting it out!)
  lights();
  // for all the markers...
  for (int i=0; i<numMarkers; i++) {
    // if the marker does NOT exist (the ! exlamation mark negates it)...
    if ((!nya.isExistMarker(i))) {
      // if the mountainGrowth is higher than zero, decrease by 0.05 (return to the zero-state), then continue to the next marker
      if (mountainGrowth[i] > 0) { 
        mountainGrowth[i] -= 0.05;
      }
      continue;
    }
    // the following code is only reached and run if the marker DOES EXIST
    // if the mountainGrowth is lower than 1, increase by 0.03
    if (mountainGrowth[i] < 1) { 
      mountainGrowth[i] += 0.03;
    }
    // the double for loop below sets the values in the 2 dimensional float array for this mountain, based on it's noiseScale, mountainHeight and index (i).
    float xoff = 0.0;
    for (int x=0; x<resX; x++) {
      xoff += noiseScale[i];
      float yoff = 0;
      for (int y=0; y<resY; y++) {
        yoff += noiseScale[i];
        val[x][y] = noise(i*10+xoff+frameCount*0.05, yoff) * mountainHeight[i]; // this sets the value
        float distance = dist(x, y, resX/2, resY/2);
        distance = map(distance, 0, resX/2, 1, 0);
        if (distance < 0) { 
          distance = -distance;
        } // this line causing the four corners to flap upwards (try commenting it out or setting it to zero)
        val[x][y] *= distance; // in the default case this makes the value approach zero towards the outer ends (try commenting it out to see the difference)
      }
    }

    // get the Matrix for this marker and use it (through setMatrix)
    setMatrix(nya.getMarkerMatrix(i));
    scale(1, -1); // turn things upside down to work intuitively for Processing users
    scale(scaler[i]); // scale the mountain by it's individual scaler
    translate(-resX/2, -resY/2); // translate to center the mountain on the marker
    // for the full resolution...
    for (int x=0; x<resX-1; x++) {
      for (int y=0; y<resY-1; y++) {
        // each face is a Shape with a fill color, together they make a colored mountain
        fill(x*20+y*20, 255-x*5, y*5);
        beginShape();
        vertex(x, y, val[x][y] * mountainGrowth[i]);
        vertex((x+1), y, val[x+1][y] * mountainGrowth[i]);
        vertex((x+1), (y+1), val[x+1][y+1] * mountainGrowth[i]);
        vertex(x, (y+1), val[x][y+1] * mountainGrowth[i]);
        endShape(CLOSE);
      }
    }
  }
  // reset to the default perspective
  perspective();
}

// this function loads .patt filenames into a list of Strings based on a full path to a directory (relies on java.io)
String[] loadPatternFilenames(String path) {
  File folder = new File(path);
  FilenameFilter pattFilter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
      return name.toLowerCase().endsWith(".patt");
    }
  };
  return folder.list(pattFilter);
}

ERROR STACK CODE

GSVideo version: 1.0.0
jp.nyatla.nyartoolkit.core.NyARException: java.lang.NullPointerException
    at jp.nyatla.nyartoolkit.core.param.NyARParam$ParamLoader.<init>(NyARParam.java:296)
    at jp.nyatla.nyartoolkit.core.param.NyARParam.createFromARParamFile(NyARParam.java:76)
    at jp.nyatla.nyar4psg.MultiMarker.<init>(MultiMarker.java:167)
    at aug_3_functional_.setup(aug_3_functional_.java:61)
    at processing.core.PApplet.handleDraw(PApplet.java:2281)
    at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:652)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:636)
    at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1284)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1106)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:981)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1295)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.NullPointerException
    at jp.nyatla.nyartoolkit.core.utils.ByteBufferedInputStream.readToBuffer(ByteBufferedInputStream.java:50)
    at jp.nyatla.nyartoolkit.core.param.NyARParam$ParamLoader.<init>(NyARParam.java:247)
    ... 25 more
java.lang.RuntimeException: java.lang.RuntimeException: Catch an exception!
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
    at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1623)
    at processing.core.PApplet.run(PApplet.java:2177)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.RuntimeException: Catch an exception!
    at processing.core.PApplet.die(PApplet.java:3937)
    at jp.nyatla.nyar4psg.MultiMarker.<init>(MultiMarker.java:172)
    at aug_3_functional_.setup(aug_3_functional_.java:61)
    at processing.core.PApplet.handleDraw(PApplet.java:2281)
    at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:652)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:636)
    at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1284)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1106)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:981)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1295)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Answers

  • (deleted other thread - was erroneously marked as 'answered' and was just philho asking for stack trace to be posted)

  • yeah it was a complete accident. Im still figuring out how to do this! Any help would be super appreciated

Sign In or Register to comment.