Currently, I am working on some Augmented Reality mobile app with Unity3D. The performance is impacted by the image quality.
Is there some way to ask webcam to auto focus with Unity3D?
As far as I know it is not possible in pure 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);
}
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");
}
}
You can find more info about creating Java plugins for Unity3D here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With