WebcamTexture rotation differs in 3D unity on Android

I am having a difficult time turning the webcam on my Android device.

Here is my scene in the editor: enter image description here

and here is the image in my phone: enter image description here

You can see the difference in rotation and scaling between the phone and the editor.

Here is the code:

using UnityEngine; using UnityEngine.UI; using System.Collections; public class Camera_pnl : MonoBehaviour { //// Use this for initialization WebCamTexture webCameraTexture; void Start() { GUITexture BackgroundTexture = gameObject.AddComponent<GUITexture>(); BackgroundTexture.pixelInset = new Rect(0,0,Screen.width,Screen.height); WebCamDevice[] devices = WebCamTexture.devices; foreach (WebCamDevice cam in devices) { if (cam.isFrontFacing ) { webCameraTexture = new WebCamTexture(cam.name); webCameraTexture.deviceName = cam.name; webCameraTexture.Play(); BackgroundTexture.texture = webCameraTexture; } } } void Update () { if (Input.GetKey (KeyCode.Escape)) { Invoke("LoadGame",0.1f); } } void LoadGame () { webCameraTexture.Stop (); webCameraTexture = null; Application.LoadLevelAsync("Game"); } } 

How can I fix this problem, so the correct rotation of the webcam is displayed on my phone?

+8
android unity3d webcam
source share
1 answer

You need to see the direction of rotation, and then rotate the preview of the captured input, this can be done by turning the preview in real time.

 int rotAngle = -webCamTexture.videoRotationAngle; while( rotAngle < 0 ) rotAngle += 360; while( rotAngle > 360 ) rotAngle -= 360; 

The following code from the Camera Capture Kit is the plugin that we use for ( https://www.assetstore.unity3d.com/en/#!/content/56673 ) - we use it for a social game / application so that the user can accept and Share photos inside the game.

You also need to flip the image when in some cases the rotation is 270 or 90 degrees. This is the code for Android.

 if( Application.platform == RuntimePlatform.Android ) { flipY = !webCamTexture.videoVerticallyMirrored; } 

You need to consider these factors when rendering a webcam preview, and when receiving pixels, the image pixels must also rotate if you want to save and share them, this is an expensive process that needs to be done frame by frame in the preview, so you need to do This is after the photo was taken once.

Greetings

+1
source share

All Articles