"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Frame Marker getting the size of the marker

Hello!

 

I am using the FrameMarkers sample for Android to develop my application. I would like to overlay data over the Marker that is detected. I managed to get the center of the marker using the method I found on these forums:

public Vec2F cameraPointToScreenPoint(Vec2F cameraPoint) {
        VideoMode videoMode = CameraDevice.getInstance ().getVideoMode(CameraDevice.MODE.MODE_DEFAULT);
        VideoBackgroundConfig config = Renderer.getInstance ().getVideoBackgroundConfig();

        WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        int screenWidth = display.getWidth();  // deprecated
        int screenHeight = display.getHeight();  // deprecated

        int xOffset = ((int) screenWidth - config.getSize().getData()[0]) / 2 + config.getPosition().getData()[0];
        int yOffset = ((int) screenHeight - config.getSize().getData()[1]) / 2 - config.getPosition().getData()[1];

        //if (isActivityInPortraitMode) {
        if(mActivity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
            // camera image is rotated 90 degrees
            int rotatedX = videoMode.getHeight() - (int)cameraPoint.getData()[1];
            int rotatedY = (int)cameraPoint.getData()[0];

            return new Vec2F(rotatedX * config.getSize().getData()[0] / (float) videoMode.getHeight() + xOffset,
                    rotatedY * config.getSize().getData()[1] / (float) videoMode.getWidth() + yOffset);
        } else {
            return new Vec2F(cameraPoint.getData()[0] * config.getSize().getData()[0] / (float) videoMode.getWidth() + xOffset,
                    cameraPoint.getData()[1] * config.getSize().getData()[1] / (float) videoMode.getHeight() + yOffset);
        }
    }

I use this method with the next code snippet:

 

Vec2F getMarkerCenter(TrackableResult trackableResult){
        CameraCalibration calib = CameraDevice.getInstance().getCameraCalibration();
        Vec2F cameraPoint = Tool.projectPoint(calib, trackableResult.getPose(), new Vec3F(0,0,0));
        return cameraPointToScreenPoint(cameraPoint);
    }

 

Overlaying the data with this position works and overlays text starting from the center of the marker. However I want to start overlaying the text from the upper left corner of the marker. I tried using the method Trackable.getSize(), but it always returns (50, 50) as the size and that is obviously not the current marker ize on the screen. How do I get the actual size of the marker on the current frame? 

AlessandroB

Tue, 04/26/2016 - 13:57

The size of a Frame Marker can be specified programmatically when you create the Marker; if the GetSize method returns a size of (50,50), this means the Marker was created with that size;

Thank you, I figured it out in the meantime. My markers are the standard A4 marker so 50 should be good. If anyone is interested here is the code that I used to get the screen coordinates of the edges of the marker:

 

Has anybody any idea how to do all the above stuff (either get the coordinates of the frame of augmentation / image target on video feedback, or its center point) in Unity ?

Hello PSPiroz,

You can get the coordinates of an Image Target by accessing the Transform of the Image Target game object.

Thanks,

-Vuforia Support