Log in or register to post comments

Find Trackable (x,y) Position on Screen ?

November 25, 2011 - 5:06am #1

Hi,

is there an way to get a Trackables position on the device screen as an (x,y)-touple ?

Re: Find Trackable (x,y) Position on Screen ?

January 4, 2012 - 2:37am #12

I solved my problem with this post, thanks.

Re: Find Trackable (x,y) Position on Screen ?

January 3, 2012 - 2:40pm #11

This post might be of interest, here's similar functionality tailored for iOS: http://ar.qualcomm.at/node/2000738

- Kim

Re: Find Trackable (x,y) Position on Screen ?

January 3, 2012 - 6:50am #10

Hi,

I'm trying to adapt it to iPhone, or find something similar. When I use this code, there is an offset.

Here is the function adapted :

- (CGPoint) cameraPointToScreenPoint:(QCAR::Vec2F)cameraPoint
{
    QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
    
    int xOffset = ((int) self.frame.size.width - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
    int yOffset = ((int) self.frame.size.height - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];
    
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
    {
        // camera image is rotated 90 degrees
        int rotatedX = videoMode.mHeight - cameraPoint.data[1];
        int rotatedY = cameraPoint.data[0];
        
        return CGPointMake(rotatedX * config.mSize.data[0] / (float) videoMode.mHeight + xOffset,
                           rotatedY * config.mSize.data[1] / (float) videoMode.mWidth + yOffset);
    }
    else
    {
        return CGPointMake(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset,
                           cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset);
    }
}

Is there something different on iPhone ?

Sorry if this is an Androïd restricted area ;)

Re: Find Trackable (x,y) Position on Screen ?

December 9, 2011 - 11:39am #9

Yep, that's exactly right, use the half width and height to find the corners.

QCAR::Vec3F(-x,y,0) would get you the upper left corner.

- Kim

Re: Find Trackable (x,y) Position on Screen ?

December 8, 2011 - 1:37pm #8
ultrah wrote:

sure, the code I posted above works just fine.

xyPoint.data contains the coordinates. I think if you modify QCAR::Vec3F(0,0,0) you could somehow get the target's corners

I could post some more code that tranfers the data to java if you want.

So I'm guessing QCAR::Vec3F(0,0,0) means the center of the target. So the xyPoint would be the x,y coords for the target center?

To get the left corner would it be this?
QCAR::Vec2F target_size = target->getSize();
GLfloat x= target_size.data[0]/2;
GLfloat y = target_size.data[1]/2;

QCAR::Vec3F(-x,y,0); ???

Re: Find Trackable (x,y) Position on Screen ?

December 2, 2011 - 12:01am #7

sure, the code I posted above works just fine.

xyPoint.data contains the coordinates. I think if you modify QCAR::Vec3F(0,0,0) you could somehow get the target's corners

I could post some more code that tranfers the data to java if you want.

Re: Find Trackable (x,y) Position on Screen ?

December 1, 2011 - 4:13pm #6

did you figure this out? How to get x,y coords of target?

Re: Find Trackable (x,y) Position on Screen ?

November 29, 2011 - 2:34am #5

thank you for your answer ksiva.

first, my knowledge in openGL is very limited, but I think the standart openGL transformations are not available in ES 2.0:
"OpenGL ES 2.0 does not support the fixed function transformation and fragment pipeline of OpenGL ES 1.x."

if I understand your second suggestions correctly, this code should get me the screen point.

[CODE" />
const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
const QCAR::CameraCalibration& cameraCalibration = tracker.getCameraCalibration();

QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration,trackable->getPose(), QCAR::Vec3F(0,0,0));
QCAR::Vec2F xyPoint = cameraPointToScreenPoint(cameraPoint);
[/CODE" />

*edit* found my error, code updated. coordinates look good, thanks !

Re: Find Trackable (x,y) Position on Screen ?

November 28, 2011 - 9:27pm #4

Or, you can use our Tool:: projectPoint method to get the point into camera space, and then use the code snippets in this thread to take the camera space point to screen space:

http://ar.qualcomm.at/node/2000570

Note that from the pose's perspective (0, 0, 0) is the center of the trackable.

- Kim

Re: Find Trackable (x,y) Position on Screen ?

November 28, 2011 - 3:01am #3

ok, so the position vector seems to be stored in [12] to [14], but x and y seem to be relative to z and z is not linear.

Is there a util to normalize x and y ?

Re: Find Trackable (x,y) Position on Screen ?

November 28, 2011 - 1:29am #2

ok, maybe I should eloborate a bit...

when a frame is rendered and a trackable is detected I can its position using:
trackable->getPose());

which gets me an undocumented '3x4 QCAR pose matrix'.

and can transform it to an (also undocumented)' QCAR::Matrix44F':
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

So how can I derive the user space position from this ?

Log in or register to post comments