Log in or register to post comments

How to stretch an image i have in Unity into a ratio that matches the image target - Using Cloud Reco

May 30, 2019 - 11:51pm #1

Hi guys, I need an Image to completely overlay the marker image i see through the camera feed. For this i might need to know what amount of pixels the marker occupies over the screen , So I could  stretch the image i have inside the unity so the image could completely overlay the target image. I have no idea how to achieve this. Also i am using cloud target to achieve this , Kindly help me know how i could successfully do the stretching. Kindly look into to the attachment too which could provide you with further idea of what i am intending to do.

Thanks.

AttachmentSize
Image icon Capture.PNG164.9 KB

How to stretch an image i have in Unity into a ratio that matches the image target - Using Cloud Reco

June 4, 2019 - 4:43pm #2

Hello,

What you've likely found is a bug in our cloud services in that the image size returned by the SDK upon a successful reco does not match the target image. At this time I have no ETA for a fix.

Workaround recommendation is to store the original image (width, height) attributes - or the original aspect-ratio - as part of the metadata of the provisioned CloudReco target. Then you can use this information to correct the displayed augmentation at run time.

Here's an example for an image of size 607 × 2000 (W x H):

  • At least, save the height of the image (heightOriginal = 2000) as metadata when provisioning the image in a Cloud Reco database
    • ("widthOriginal": "607"; "heightOriginal": "2000")
  • At runtime, when the image is detected by the cloud service, the ImageTarget has the wrong sizes
    • width = 607.0, height = 1869.7 (as returned by the Vuforia Engine APIs)
  • In order to get the correctly sized overlay, you'll have to correct the aspect ratio of the augmentation to be shown. This is done either by directly changing the vertex coordinates of the rectangular polygon, or by inserting a correction transformation in the scene graph in front of the polygon. This transformer equalizes the image - only along one axis at a time, as the other is correctly adapted to the tracked target.
    • Another way would be to fix the ImageTarget size with setSize(), but we recommend against this as it can cause additional problems.
  • Depending on the format of the image (portrait or landscape), there are different formulas in the pseudo code below where:
    • heightOriginal - original height of the image, as stored in the Cloud Target's metadata
    • width and height - width and height of the detected ImageTarget via getSize() at runtime
    • sX or sY - scaling factors along the X or Y axis for correction
// init with current values of the detected ImageTarget
widthCorrected = width;
heightCorrected = height;

// portrait format
if (width <height) {   
    sX = height / heightOriginal;   
    widthCorrected = sX * width;
}

// landscape format
If (width> height) {  
    sY = heightOriginal / height;  
    heightCorrected = sY * height;
}

// Bonus: square images do not need to be corrected if width == height!
renderObject.setSize (widthCorrected, heightCorrected);

Thanks,

Vuforia Engine Support

Log in or register to post comments