AR: GetPose of Camera (Pose class)

Hi there,
i am working with Processing for Android for a AR App and I am trying to work with the camera position (e.g. to rotate things according to camera rotation etc.)
I used the commented out lines in the “Cubes” Example:
ARSurface surface = (ARSurface) getSurface();
println(surface.camera.getPose());

And thats what was printed:
t:[x:-0.397, y:-0.184, z:0.087], q:[x:0.56, y:0.44, z:0.43, w:-0.56]

It seems that this is a ‘Pose’ class (https://developers.google.com/ar/reference/java/com/google/ar/core/Pose?hl=en)
but I couldn’t find a way to access the parameters one by one as it is not an array list but a class it seems. Even tried to convert it to a string but that did not work either.

Any ideas? Thanks a lot!

Hi,

don’t understand your issue !?

The class, resp. the returned object of the class, provides you with the informations about via the methods listed in the reference you linked!?

The toString means
t=transformation
q=rotation as quaternion

Cheers
— mnse

Hi mnse,

thanks for your reply! As this is clear for you and not for me, I guess I cannot read the Reference of Pose properly, because I am not familiar enough with Java to transfer this information into my project. I see that there are functions on how to get e.g. the tx of the Pose, but I cannot apply them. Whenever I try to declare a new Pose I get "The class “Pose” doesn’t exist. Can you help me how to implement that? I just want to get e.g. the tx as a float.

My sketch is as simple as that now:

import processing.ar.*;

void setup() {
  fullScreen(AR);
}

void draw() {
  // The AR Core session, frame and camera can be accessed through Processing's surface object
  // to obtain the full information about the AR scene:
//    ARSurface surface = (ARSurface) getSurface();
//    surface.camera.getPose();
//    surface.frame.getLightEstimate();

  
  lights();
  ARSurface surface = (ARSurface) getSurface();
  if (mousePressed) {
     println(surface.camera.getPose());
  }
  
}

Hi,
try this …

import processing.ar.*;

void setup() {
  fullScreen(AR);
}

void draw() {
  // The AR Core session, frame and camera can be accessed through Processing's surface object
  // to obtain the full information about the AR scene:
//    ARSurface surface = (ARSurface) getSurface();
//    surface.camera.getPose();
//    surface.frame.getLightEstimate();

  
  lights();
  ARSurface surface = (ARSurface) getSurface();
  if (mousePressed) {
     float tx = surface.camera.getPose().tx();
     println(tx);
  }  
}

or… if you want the Pose Object …

import processing.ar.*;
import com.google.ar.core.*;

void setup() {
  fullScreen(AR);
}

void draw() {
  // The AR Core session, frame and camera can be accessed through Processing's surface object
  // to obtain the full information about the AR scene:
//    ARSurface surface = (ARSurface) getSurface();
//    surface.camera.getPose();
//    surface.frame.getLightEstimate();

  
  lights();
  ARSurface surface = (ARSurface) getSurface();
  if (mousePressed) {
     // ie.
     Pose p = surface.camera.getPose();
     float tx = p.tx();
     float ty = p.ty();
     float tz = p.tz();
     println(tx + "/" + ty + "/" + tz);
  }  
}

Perfect thanks a lot! Thats what I was looking for. I didn’t know you could use it like this. Now theres a lot more possibilities to play around with fixed objects related to world coordinates and those related to the movement!
This is a test sketch to with a fixed box that rotates depending on ty and another box that moves with the transition of the phone.

import processing.ar.*;
import com.google.ar.core.*;

void setup() {
  fullScreen(AR);
}

void draw() {
  lights();
    
  ARSurface surface = (ARSurface) getSurface();
  Pose p = surface.camera.getPose();
  float tx = p.tx();
  float ty = p.ty();
  float tz = p.tz();

  if (mousePressed) {
     println(tx + "/" + ty + "/" + tz);
  }  
  
  stroke(204, 102, 0);
  strokeWeight(10);
  
  pushMatrix();
  translate(0,0,-1);
  rotateY(ty*3);
  fill(0,0,200);
  box(0.1);
  popMatrix();

  pushMatrix();
  translate(tx,ty,tz-1);
  fill(0,200,200);
  box(0.1);
  popMatrix();
  
  line(0,0,-1,0,0.3,-1);
  line(0,0,-1,tx,ty,tz-1);
  line(tx,ty+0.3,tz-1,tx,ty,tz-1);
  line(tx,ty+0.3,tz-1,0,0.3,-1);
} 

Next step would be to have a box fixed to the view thats always 1 meter in front of the camera. I guess the use of the quaternions might be a problem here. Or is there a function which is doing that more simple?
Anyway thats something for later. Thanks again!

Not sure, but I bet if you’re playing around, resp. dealing with it long enough, you’ll find a way! :grin:

Cheers
— mnse