Topic locked

Front Camera Upsidedown Nexus6

March 23, 2015 - 10:46am #1

Vuforia SDK Version: Vuforia Unity 4-0-103 -
Description with steps to reproduce:

Greetings dear Vuforia-Team,

we are currently updating one of our AR apps for our client. First we updated to Unity5 (Pro Desktop, Pro iOS and Pro Android) and Vuforia4 using the classic plan. Then we included a new feature, that uses the front-camera of the device for the app. We successfully testet the app with all of our devices (reaching from the Galaxy S series over some HTC to all Nexus devices) and it works with all of them beside of one device: the Nexus6. On the Nexus6 the front-camera-view is updsidedown. The tracking on the upsidedown camera-image is correct, mentioned that it is therefore also upsidedown.

We made some tests with the physical orientation of the camera chips (android.hardware.camera2.CameraCharacteristics; SENSOR_ORIENTATION) and almost all devices have a angle of 270 degrees with the front cam. The Nexus6 has a angle of only 90 degrees, which calculational would result in exact the 180 degrees, that the camera-image is rotated. Because the Nexus6 is a main target-device for our client we have to focus on fixing this bug, but ran out of possibilites to do this.

We are looking forward to hear from your team, because we have a hard deadline at the end of march.

 

Yours sincerely,

Peter Huber

-
Development OS (Mac OS X, Windows, Linux): Windows -
Mobile OS and Version: Android 5.0 -
Mobile Device Manufacturer and Model name: Google Nexus6 -
Do the Vuforia Sample Applications show the same behavior?:

Front Camera Upsidedown Nexus6

March 25, 2015 - 8:11am #6

Great, glad to hear this works for you.

We should address this issue in a future release, but curently I am unable to say when exactly.

Front Camera Upsidedown Nexus6

March 25, 2015 - 4:26am #5

Thank you guys very much for your quick help! That workaround, applied only on devices with the front-cam installed with 90 degrees orientation, does solve our problem.
Will this issue be fixed in an upcoming update of Vuforia, so we have to remove this workaround in with future releases of our app?

Front Camera Upsidedown Nexus6

March 24, 2015 - 4:35pm #4

For your device you may need to add another flag to skip the first OnPreCull () call.

private bool mFirstCall = true;

void OnPreCull () {
    if (!mFlipped) {
        if(!mFirstCall)  // don't flip on first call to OnPreCull()
        {
            Camera cam = this.transform.parent.GetComponent<Camera>();
            Vector3 flipScale = new Vector3 (mFlipHorizontal ? -1 : 1, mFlipVertical ? -1 : 1, 1);
            Matrix4x4 projMat = cam.projectionMatrix * Matrix4x4.Scale(flipScale);
            cam.projectionMatrix = projMat;
            mFlipped = true;
        }
        mFirstCall = false;
    }
}

 

Front Camera Upsidedown Nexus6

March 24, 2015 - 10:01am #3

Note: you should only apply this workaround on the faulty device  / camera.

 

Front Camera Upsidedown Nexus6

March 24, 2015 - 9:56am #2

Hi,

if the front camera appears upside down, but the augmentation is consistent with the background image,

you should be able to workaround this by adding the following script to the Camera object (see the Camera gameobject under the ARCamera root object):

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Camera))]
public class CameraRotate : MonoBehaviour {

	private bool mFlipped = false;
	private bool mFlipVertical = true;
	private bool mFlipHorizontal = false;


	void OnPreCull () {
		if (!mFlipped) {
			Camera cam = GetComponent<Camera>();
			Vector3 flipScale = new Vector3 (mFlipHorizontal ? -1 : 1, mFlipVertical ? -1 : 1, 1);
			Matrix4x4 projMat = cam.projectionMatrix * Matrix4x4.Scale(flipScale);
			cam.projectionMatrix = projMat;
			mFlipped = true;
		}
	}
	
	void OnPreRender () {
		if ((mFlipVertical && !mFlipHorizontal) || 
		    (mFlipHorizontal && !mFlipVertical)) {
			GL.SetRevertBackfacing (true);
		}
	}

	// Set it to false again because we don't want to affect all other cameras.
	void OnPostRender () {
		if ((mFlipVertical && !mFlipHorizontal) || 
		    (mFlipHorizontal && !mFlipVertical)) {
			GL.SetRevertBackfacing (false);
		}
	}
}

In the code above, please note that the boolean flag mFlipHorizontal may have to be set to true (if you want a 180 degress rotation); otherwise you can try both with true and false, and see which one fixes your problem.

Please Let me know if that works.

 

Topic locked