Topic locked

get projection of target center on mobile screen

May 25, 2014 - 5:25am #2

I'm trying to get the sceen point where the trackable center is drawn at.

I use the image target example:

This is the code of the cameraPointToScreenPoint from here https://developer.vuforia.com/resources/dev-guide/screen-coordinates

which i changed to java code as following

private Vec2F cameraPointToScreenPoint(Vec2F cameraPoint)
    {
    	int screenWidth = vuforiaAppSession.getScreenWidth();
    	int screenHeight = vuforiaAppSession.getScreenHeight();
        VideoMode videoMode = CameraDevice.getInstance().getVideoMode(CameraDevice.MODE.MODE_DEFAULT);
        VideoBackgroundConfig config = Renderer.getInstance().getVideoBackgroundConfig();
        int xOffset = (int) (((int) screenWidth - config.getSize().getData()[0]) / 2.0f + config.getPosition().getData()[0]);
        int yOffset = (int) (((int) screenHeight - config.getSize().getData()[1]) / 2.0f - config.getPosition().getData()[1]);
        if (vuforiaAppSession.isPortrait())
        {
            // camera image is rotated 90 degrees
            int rotatedX = (int) (videoMode.getHeight() - cameraPoint.getData()[1]);
            int rotatedY = (int) cameraPoint.getData()[0];
            float f1 = rotatedX * config.getSize().getData()[0] / (float) videoMode.getHeight() + xOffset;
            float f2 = rotatedY * config.getSize().getData()[1] / (float) videoMode.getWidth() + yOffset;
            Vec2F vf = new Vec2F (f1, f2);
            return vf;
        }
        else
        {
        	float f1 = cameraPoint.getData()[0] * config.getSize().getData()[0] / (float) videoMode.getWidth() + xOffset;
        	float f2 =  cameraPoint.getData()[1] * config.getSize().getData()[1] / (float) videoMode.getHeight() + yOffset;
            Vec2F vf = new Vec2F(f1, f2);
        	return vf;
        }
    }

 

And i use this method in the rendererFrame method  as following:

Vec3F point = new Vec3F(result.getPose().getData()[3], result.getPose().getData()[3+4*1], result.getPose().getData()[3+4*2]);
            Vec2F vec = cameraPointToScreenPoint(Tool.projectPoint(CameraDevice.getInstance()
                    .getCameraCalibration(), result.getPose(), point));
            Log.i(LOGTAG, "screen point");
            Log.i(LOGTAG, Arrays.toString(vec.getData()));

 

The problem now is: values returned by this method are

05-25 15:20:05.446: I/ImageTargetRenderer(16629): [1729.3569, 16412.361]

05-25 15:20:05.506: I/ImageTargetRenderer(16629): [4942.0474, 15629.771]
05-25 15:20:05.576: I/ImageTargetRenderer(16629): [9495.927, 14752.8125]
 

I think these values are too large to be screen points.

Am i missing something here ? or there is a better way to get the center value of the trackable in the screen range.

 

 

get projection of target center on mobile screen

May 26, 2014 - 3:37pm #1

Thanks i figured where the problem is.

Topic locked