首页 > 解决方案 > Unity WebcamTexture 高级设置(曝光、对焦、缩放)

问题描述

我的相机源在使用 WebcamTexture 的 Unity 中工作。根据https://docs.unity3d.com/ScriptReference/WebCamTexture.html,没有更改曝光或焦点设置的功​​能。

只是要清楚:

  1. 有什么办法可以改变 WebcamTexture 的曝光?
  2. 如果没有,有没有其他方法可以在使用 WebcamTexture 的情况下调整曝光?
  3. 如果没有,我可以在 Unity 中使用哪些广泛使用的 API/工具来获取具有这些可调整设置的摄像头供稿?

标签: c#unity3dcamera

解决方案


Is there any way to change the exposure of WebcamTexture?

No. You can on Android with AndroidJavaObject but that's a hack and can stop working each time there is Unity update. Also, it will only work on Android but not on iOS, Windows, Mac and other platforms.

If not, is there any other way to adjust the exposure without using WebcamTexture?

Again, no. You can't modify the camera settings while using WebcamTexture.

If not, what are some widely used API/tools that I can use in Unity for getting camera feed with these adjustable settings?

The only way to be able to modify the camera settings you mentioned is to create a camera API plugin for each platform. This is not easy to do since you have to know many programming languages to get it working such as Java for Android, Objective-C for iOS and Mac, C++ for Windows and Linux and Javascript for WebGL then use C# to put them together. It's really time-consuming to make this and therefore better to use an existing plugin.

The best one out there is the NatCam plugin. This plugin can control the exposure, focus and zoom of the camera but it's not free. It's worth it.

You can set the exposure and the exposure bias as:

DeviceCamera.RearCamera.ExposureMode = ExposureMode.Locked;
NatCam.Camera.ExposureBias = NatCam.Camera.MinExposureBias;

To set the Focus Mode:

NatCam.Camera.FocusMode = FocusMode.TapToFocus | FocusMode.AutoFocus;

To zoom the camera:

NatCam.Camera.ZoomRatio = 2.0f;

You can find the complete tutorial for NatCam here.


推荐阅读