nyatla / NyARToolkit-for-Processing

NyARToolkit for Processing
GNU Lesser General Public License v3.0
51 stars 23 forks source link

getNyID crashes the cam #9

Open jpupper opened 6 years ago

jpupper commented 6 years ago

Hello ! , im trying to get wich marker has been tracked.

I supposed is with the function "getNyId" ? , but this function is crashing everytime a new marker es read by the cam.

nyatla commented 6 years ago

Can you present an stack trace?

jpupper commented 6 years ago

Can you present an stack trace?

The program is not crashing , is only freezing the cam. This is the log of the stack trace before the cam freezes :

java.lang.Exception
    at batallon601_2.draw(batallon601_2.java:88)
    at processing.core.PApplet.handleDraw(PApplet.java:2437)
    at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:859)
    at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
    at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
    at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
    at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
    at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
    at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

This is my code thought :


import processing.video.*;
import jp.nyatla.nyar4psg.*;

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

Capture cam;
MultiMarker nya;

boolean oscFlag = false;
boolean oscFlagDesactivate = false;

float lastime;
float duration = 3000;

int counter;

void setup() {
  size(640, 480, P3D);
  colorMode(RGB, 100);
  println(MultiMarker.VERSION);
  initcam();

  nya=new MultiMarker(this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
  nya.addARMarker(loadImage("55.jpg"), 16, 25, 80);
  nya.addARMarker(loadImage("44.jpg"), 16, 25, 80);
  nya.addARMarker(loadImage("33.jpg"), 16, 25, 80);
  nya.addARMarker(loadImage("22.jpg"), 16, 25, 80);
  cam.start();

  //myRemoteLocation = new NetAddress("192.168.0.106", 8080); //SENDER
  oscP5 = new OscP5(this, 9045); //RECEIVERess
  myRemoteLocation = new NetAddress("192.168.0.59", 7000); //SENDER
  lastime = millis();
}

void draw()
{  

  if (cam.available() == true) {

    cam.read();

    nya.detect(cam);
    nya.drawBackground(cam);//frustumを考慮した背景描画
   // for (int i=0; i<4; i++) {
      if (nya.isExistMarker(0)) {
        //if (!oscFlag && nya.getLife(0) > 10) {

          oscFlagDesactivate = true;      
          OscMessage myMessage = new OscMessage("/layer1/clip2/connect");    
          myMessage.add(1);
          oscP5.send(myMessage, myRemoteLocation); 
          oscFlag = true;
          lastime = millis();

          OscMessage myMessage2 = new OscMessage("/activeclip/audio/position/values");    
          myMessage2.add(0.0);
          oscP5.send(myMessage2, myRemoteLocation); 
          counter++;

          println("ACTIVATE MARKER COUNTER:"+counter+"ID: "+nya.getNyId(0));
        //}
      } else {
        if (oscFlagDesactivate && millis()-lastime > duration) {
          oscFlagDesactivate = false;
          oscFlag = false;

          OscMessage myMessage = new OscMessage("/layer1/clip1/connect");    
          myMessage.add(1);
          oscP5.send(myMessage, myRemoteLocation); 

          OscMessage myMessage2 = new OscMessage("/activeclip/audio/position/values");    
          myMessage2.add(0.0);
          oscP5.send(myMessage2, myRemoteLocation); 

          counter++;
          println("DESACTIVATE: "+counter);
        }
      }
    //}
  }
}

void initcam() {

  String[] cameras = Capture.list();
  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 680, 420);
  } 
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    printArray(cameras);
    cam = new Capture(this, cameras[0]);
    cam.start();
  }
}

All im trying to do is sending a different signal for each target thought OSC .

The OSC part works fine, but i dont seem to have a way to know wich ID.