Log in or register to post comments

Get the Coordinates of the AR

September 4, 2012 - 6:00am #1


I would like to know is this is possible to get the coordinates on the screen of the AR ? (the smallest square which contents the whole AR).

if yes, can anyone helps me ?

Thanks in advance.

Get the Coordinates of the AR

January 12, 2015 - 9:10am #4

I'm aware it's a 2 years old answer, but I have another question upon this. I don't understand what kind of Vec3F I should provide to the projectPoint method.


QCAR_API Vec2F projectPoint(const CameraCalibration& calib, const Matrix34F& pose, const Vec3F& point);


I've tried with QCAR::Vec3F( 0.f, 0.f, 0.f ) assuming that it was the center of the target coordinate, but I don't get good results. Is there an example where I can see the use of projectPoint ? I didn't find it in the Samples or on the internet.


Thank you!

Get the Coordinates of the AR

September 5, 2012 - 4:02am #3

Hi GabrielS,

Apologies for the delay.

You need to go via the pose matrix which returns the 3D position of the target in the center, assuming the camera is at (0,0,0), and then convert this into 2D camera space, and then transfor this into screen space.

If you look in \include\QCAR you will find the projectPoint() function in tool.h which will help you with the first part:


    /// Projects a 3D scene point into the camera image(device coordinates)

    /// given a pose in form of a 3x4 matrix.


     *  The projectPoint() function takes a 3D point in scene coordinates and

     *  transforms it using the given pose matrix. It then projects it into the

     *  camera image (pixel coordinates) using the given camera calibration.

*  Note that camera coordinates are usually different from screen

*  coordinates, since screen and camera resolution can be different.

*  Transforming from camera to screen coordinates requires another

*  transformation using the settings applied to the Renderer via the

*  VideoBackgroundConfig structure.


    QCAR_API Vec2F projectPoint(const CameraCalibration& calib,

                                const Matrix34F& pose, const Vec3F& point);


For the second part the following code snippet will take the camera space point returned by the above method, and transform it into screen space.

    QCAR::Vec2F 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) screenWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];

        int yOffset = ((int) screenHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];


        if (isActivityInPortraitMode)


            // camera image is rotated 90 degrees

            int rotatedX = videoMode.mHeight - cameraPoint.data[1];

            int rotatedY = cameraPoint.data[0];


            return QCAR::Vec2F(rotatedX * config.mSize.data[0] / (float) videoMode.mHeight + xOffset,

                               rotatedY * config.mSize.data[1] / (float) videoMode.mWidth + yOffset);




            return QCAR::Vec2F(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset,

                               cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset);



All of the above will help you get the central point of the AR.

If you want to get all four coordinates of an image target, then what you could do is to overlay a plane on top and calculate the above for all four corners.

Hope this makes sense.




Get the Coordinates of the AR

September 5, 2012 - 1:41am #2

Hi (again ;) ),

I try to get the Z from the depth buffer... but it looks like when i do that :

glReadPixels((GLint) xcoord, (GLint) ycoord, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth1);

It looks like depth1 value is always equal to 0..

Please help if you've an idea ;)

Thanks in advance.


Log in or register to post comments