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?
Hello PSPiroz,
You can get the coordinates of an Image Target by accessing the Transform of the Image Target game object.
Thanks,
-Vuforia Support