Log in or register to post comments

3D Object Position

March 7, 2012 - 9:09am #1

Hi,
I want to get the 2D-Screen-Coordinate for an 3D-Object to place a tap-event (Tap Event works fine only the 2D-Screen-Coordinate for an 3D-Object is needed).
My first step was to calculate the 2D-Screen-Coordinate for the tracking image.

Quote:

QCAR::Matrix44F modelViewMatrix =
QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
QCAR::Vec2F screenPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(0, 0, 0));

//LOG("camera point: %f, %f", screenPoint.data[0], screenPoint.data[1]);

QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();

float xOffset = ((float) screenWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
float yOffset = ((float) screenHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];

float x = (screenPoint.data[0] * config.mSize.data[0]) / ((float) videoMode.mWidth + xOffset);
float y = (screenPoint.data[1] * config.mSize.data[1]) / ((float) videoMode.mHeight + yOffset);

My next step was to insert a 3D-Object which I translated a little bit:

Quote:

SampleUtils::translatePoseMatrix(50, -50, 50,
&modelViewMatrix.data[0]);

I know that every Object has it's origin at 0,0,0 and that's the center from the tracking image which I already got. My suggestion was it to use the translate parameter as an offset. The result was very confusing.
After this fail, I searched inside of the QCAR/Include Folder for some help and found the Tool.h file with a method called projectPoint. What I have done now is to paste the values, which i used to translate my 3D-Object (50,-50,50), instead of 0,0,0:

Quote:

QCAR::Vec2F object = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(50, -60, 50)); ("-60" works better for me)

I'm not quite convinced about the result. It seems to work but i'm not sure. Any comment on this case, is my last attempt right?

Robert

Re: 3D Object Position

March 7, 2012 - 4:49pm #3
ksiva wrote:

The QCAR::Tool::ProjectPoint method returns a point in camera image space. You have to do a little more work to get this in screen space. See this thread: http://ar.qualcomm.at/node/2000570

- Kim

Hi Kim, I forgot some lines of code after projectPoint:

Quote:

float xObject2 =(object.data[0]* config.mSize.data[0]) / ((float) videoMode.mWidth + xOffset);
float yObject2 =(object.data[1]* config.mSize.data[1]) / ((float) videoMode.mHeight + yOffset);

Robert

Re: 3D Object Position

March 7, 2012 - 3:43pm #2

The QCAR::Tool::ProjectPoint method returns a point in camera image space. You have to do a little more work to get this in screen space. See this thread: http://ar.qualcomm.at/node/2000570

- Kim

Log in or register to post comments