Log in or register to post comments

SampleApplicationSession.configureVideoBackground

May 23, 2016 - 11:47am #1

Vuforia SDK Version: 5.5.9 -

Hi, If I understand correctly the function "configureVideoBackground" is supposed to do a ratio-stretch, that is, figuring out the maximum size that the camera feed will fit on screen while retaining its original aspect ratio.

If this is indeed the goal of this function, then it appears to be broken for cases where the aspect ratio of the screen is superior (more landscapey) than the camera feed. For example on ODG R-7 the screen can be 1280x720 while the camera returns something like 672x380. Both are landscape, but the screen has an even greater aspect ratio than the camera. In this case the function sets the video background to 1280x723. This is larger than the screen. If the screen is 2560x720, the function sets the background to 2560x1447.

 

I'm using the following replacement function which I think is more correct and simpler.

float screenAspectRatio = displaySize.x / (float)displaySize.y;
float cameraAspectRatio = vm.getWidth() / (float)vm.getHeight();

if (cameraAspectRatio < screenAspectRatio)
{
    ySize = displaySize.y;
    xSize = (int)(ySize * cameraAspectRatio);
}
else
{
    xSize = displaySize.x;
    ySize = (int)(xSize / cameraAspectRatio);
}

 

This gives me the expected 1273x720. -

Development OS (Mac OS X, Windows, Linux): Linux -
Mobile OS and Version: Android 4.4.2 -
Mobile Device Manufacturer and Model name: ODG R7-W -
Do the Vuforia Sample Applications show the same behavior?: Yes.

SampleApplicationSession.configureVideoBackground

May 24, 2016 - 7:33pm #3

Yes, the function I posted does ratio-stretch, so you get black bands on the side or above and below, but the entire camera feed is seen and at the correct aspect ratio.

Isn't it more desirable to see the entire camera feed rather than only part of it, even if it's at the expense of black bands?

SampleApplicationSession.configureVideoBackground

May 24, 2016 - 3:17pm #2

Hello,

Your understanding of the purpose of the API is accurate. However, since the camera aspect ratio is different from the screen aspect ratio, the function simply scales the camera image so that one dimension (e.g. the width) matches the screen width. While the other dimension will be larger than the screen dimension (e.g. height).

In this case, the camera image will be larger than the screen. This is because the camera image maintains its original aspect ratio and fills the screen entirely (so if one dimension matches the screen, the other dimension must necessarily exceed the screen). Failing to do so would result in camera stretched (unwanted) or black side bands (e.g. letterboxing).

Thanks.

Log in or register to post comments