如何使用按钮切换/更改前后Vuforia AR相机? [英] How to Switch/Change Front and back Vuforia AR Camera using a button?
问题描述
我正在使用Unity开发AR移动应用.
I am developing an AR mobile app using Unity.
为此,我添加了Vuforia AR相机,它可以与我的笔记本电脑相机配合使用,并且可以在图像目标上显示3D模型.
For that I have added a Vuforia AR Camera, it works fine with my Laptop cam, and it shows a 3D model on an image target.
我的问题是如何使用一个简单的按钮在Android设备上的前摄像头和后摄像头之间切换?
My quastion is how can I switch between front cam and back cam on Android device using a simple button?
我已经尝试过以下代码示例在笔记本电脑摄像头和外部摄像头之间进行切换:
I have tried this code example to switch between the Laptop cam and an external webcam :
using UnityEngine;
using Vuforia;
public class SwitchCamera : MonoBehaviour
{
private bool cameraMode = false;
public void OnCameraChangeMode()
{
CameraDevice.CameraDirection currentDir = CameraDevice.Instance.GetCameraDirection();
if (!cameraMode)
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_FRONT);
Debug.Log("Back Camera");
}
else
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_BACK);
Debug.Log("Front Camera");
}
}
private void RestartCamera(CameraDevice.CameraDirection newDir)
{
CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();
CameraDevice.Instance.Init(newDir);
CameraDevice.Instance.Start();
}
}
推荐答案
Hello Montacer,您只是忘了更改cameramode值.
Hello Montacer, You just forgot to change the cameramode value.
CameraDevice.CameraDirection currentDir = CameraDevice.Instance.GetCameraDirection();
if (!cameraMode)
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_FRONT);
cameramode = true;
Debug.Log("Back Camera");
}
else
{
RestartCamera(CameraDevice.CameraDirection.CAMERA_BACK);
cameramode = false;
Debug.Log("Front Camera");
}
除此之外,一切看起来都不错.希望这会有所帮助.
other than that everything looks great.hope this helps.
这篇关于如何使用按钮切换/更改前后Vuforia AR相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!