问题描述
当前,我正在使用Unity3D开发一些增强现实移动应用程序.性能受图像质量的影响.
Currently, I am working on some Augmented Reality mobile app with Unity3D. The performance is impacted by the image quality.
是否可以通过Unity3D要求网络摄像头自动对焦?
Is there some way to ask webcam to auto focus with Unity3D?
推荐答案
据我所知,在纯Unity3D中是不可能的.
As far as I know it is not possible in pure Unity3D.
但是,如果您正在Android上进行开发,则可以用Java编写一个插件,该插件设置自动对焦并从Unity3D调用它.
However, if you are developing this on Android, you can write a plugin in java, which sets autofocus and call it from Unity3D.
public void enableAutofocus() {
camera = camera.open();
Camera.Parameters parameters = camera.getParameters();
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
camera.setParameters(parameters);
}
然后,您必须从Unity3D调用您的课程:
And then, you have to call your class from Unity3D:
public class ExampleClass : MonoBehaviour {
void Start() {
AndroidJavaObject jo = new AndroidJavaObject("com.mypackage.Autofocus");
jo.Call("enableAutofocus");
}
}
您可以在此处中找到有关为Unity3D创建Java插件的更多信息.
You can find more info about creating Java plugins for Unity3D here.
这篇关于如何要求网络摄像头使用Unity3D自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!