Log in or register to post comments

Get Trackable Angle

May 5, 2016 - 4:14am #1

Is there a way to get trackable angle such as in Euler angle? After the trackable is detected if I change the angle of the device relative to the trackable I want to know the angle between camera and trackable.

Get Trackable Angle

September 16, 2016 - 7:36am #7

Vuforia::Vec3F cameraPosition(cameraPosX, cameraPosY, 0);

to

 

Vuforia::Vec3F cameraPosition(cameraPosX, cameraPosY, cameraposZ);

 

may work.

Get Trackable Angle

May 18, 2016 - 3:32am #6

Also I tried the sample code from the following link

https://developer.vuforia.com/forum/qcar-api/direction-marker#comment-2002780

And the code is as follows,

Vuforia::Vec3F cameraPosition(cameraPosX, cameraPosY, 0);
// project both vectors to the Y/Z plane
// reverse the camera position to get a vector pointing to the target
Vuforia::Vec3F projectedDirectionToRight(0, -cameraPosition.data[1], -cameraPosition.data[2]);
Vuforia::Vec3F projectedCameraRight(0, cameraRight.data[1], cameraRight.data[2]);

// project both vectors to the X/Z plane
// reverse the camera position to get a vector pointing to the target
Vuforia::Vec3F projectedDirectionToUp(-cameraPosition.data[0], 0, -cameraPosition.data[2]);
Vuforia::Vec3F projectedCameraUp(cameraUp.data[0], 0, cameraUp.data[2]);

// project both vectors to the X/Y plane
// reverse the camera position to get a vector pointing to the target
Vuforia::Vec3F projectedDirectionToTarget(-cameraPosition.data[0], -cameraPosition.data[1], 0);
Vuforia::Vec3F projectedCameraLookAt(cameraLookAt.data[0], cameraLookAt.data[1], 0);

// normalize the projected vectors
projectedDirectionToTarget = MathUtils::Vec3FNormalize(projectedDirectionToTarget);
projectedDirectionToRight = MathUtils::Vec3FNormalize(projectedDirectionToRight);
projectedDirectionToUp = MathUtils::Vec3FNormalize(projectedDirectionToUp);
projectedCameraLookAt = MathUtils::Vec3FNormalize(projectedCameraLookAt);
projectedCameraRight = MathUtils::Vec3FNormalize(projectedCameraRight);
projectedCameraUp = MathUtils::Vec3FNormalize(projectedCameraUp);

// find the dot and cross products of the normalized vectors
CGFloat dotX = MathUtils::Vec3FDot(projectedDirectionToRight, projectedCameraRight);
CGFloat dotY = MathUtils::Vec3FDot(projectedDirectionToUp, projectedCameraUp);
CGFloat dotZ = MathUtils::Vec3FDot(projectedDirectionToTarget, projectedCameraLookAt);
// the angle between two vectors is the acos of the dot product
CGFloat angleX = acos(dotX) * 180.0f / M_PI;
CGFloat angleY = acos(dotY) * 180.0f / M_PI;
CGFloat angleZ = acos(dotZ) * 180.0f / M_PI;

From the above code base I got the X and Y angle.

How can I get the angle of rotation of the trackable (for example the target image is flat respective to the camera or screen and the image is rotated to some angle like sideways, upside down etc)?

Get Trackable Angle

May 12, 2016 - 1:02am #5

I used below lines of code

float xAngle = (float) Math.acos(SampleMath.Vec3FDot(cameraRight, new Vec3F(1, 0, 0)) / Math.sqrt(SampleMath.Vec3FDot(cameraRight, cameraRight)));
float yAngle = (float) Math.acos(SampleMath.Vec3FDot(cameraUp, new Vec3F(0, 1, 0)) / Math.sqrt(SampleMath.Vec3FDot(cameraUp, cameraUp)));
float zAngle = (float) Math.acos(SampleMath.Vec3FDot(cameraDir, new Vec3F(0, 0, 1)) / Math.sqrt(SampleMath.Vec3FDot(cameraDir, cameraDir)));
 

from the link https://developer.vuforia.com/forum/qcar-api/problems-calculating-camera-orientation-and-distance-target

If I rotate the camera left to right or right to left, I'm getting value for yAngle properly, whereas if rotate the camera top to bottom or bottom to top the value for xAngle is not changing and it is always approximately equal to 90 degree.

Am I doing anything wrong?

Get Trackable Angle

May 11, 2016 - 11:57pm #4

I got the Matrix using the following code

Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose());

and I did the following code

SampleApplicationUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScaleNormal, &modelViewMatrix.data[0]);
SampleApplicationUtils::scalePoseMatrix(kObjectScaleNormal, kObjectScaleNormal, kObjectScaleNormal, &modelViewMatrix.data[0]);
SampleApplicationUtils::multiplyMatrix(&vapp.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);

now how should I get the X, Y and Z angles?

 

I have to fix a 3D object like tea pot used in the sample application and I should be able to view the 3D in different angles based on the angle between the Camera and the trackable.

I tried the below link and I was able to get X, Y, Z angles, if use this the rotation of the 3D object is not as smooth as the tea pot sample.

https://developer.vuforia.com/forum/qcar-api/problems-calculating-camera-orientation-and-distance-target

Get Trackable Angle

May 11, 2016 - 11:00pm #3

The modelViewMatrix.data  is an aray of 16 floats that contains the values of the pose local axis that I was referring to; 

elements 0,1,2 of the array above will give you the first axis, elements 4,5,6 will give the second local axis (Y) and elements 8,9,10 will give you the third axis.

see also:

http://www.songho.ca/opengl/gl_transform.html

 

 

 

Get Trackable Angle

May 10, 2016 - 11:38pm #2

Once you get a Trackable Pose matrix, you can extract its column vectors, which represent the 3 oriented local axis (X,Y,Z) of your Trackable reference frame, with respect to the camera reference frame.

You can then compute the angles of thoese axis using basic trigonometric maths.

 

Log in or register to post comments