【问题标题】:How to set the tango camera exposure and iso parameters from c#/Unity如何从 c#/Unity 设置探戈相机曝光和 iso 参数
【发布时间】:2016-04-07 17:32:25
【问题描述】:

我正在尝试禁用相机自动曝光。根据此处的文档 https://developers.google.com/project-tango/apis/c/reference/group/config-params ,可以在配置中设置 color_mode_auto、color_exp 和 color_iso 值。

我尝试在 TangoConfig 对象在 TangoApplication.cs 中创建后立即为其设置值,但我收到一条警告,说这些 TangoConfig 无法设置相关键(键字符串名称直接取自上面的文档) .

是否可以在 C# 中设置这些值,如果可以,正确的设置位置在哪里?

【问题讨论】:

  • 配置更改需要在服务连接之前完成。你就是这么干的吗?
  • 我相信是的,杰森。我刚刚尝试了另一个测试,我在 _TangoConnect() 调用之前直接设置了一个参数(第 506 行,TangoApplication.cs),这是我得到的结果: TangoConfig.SetBool() 无法设置键:config_color_mode_auto 和值: 错误

标签: google-project-tango


【解决方案1】:

您可能需要编写一个插件来设置 Unity 相机实例上的 iso 值和曝光。您可以通过一些涉及解析相机实例的棘手黑客技术将实例引用到正在运行的相机的引用中,然后您应该能够注入 iso/exposure 参数。

此类插件的一个示例是 Unity 的 Camera Capture Kit (https://www.assetstore.unity3d.com/en/#!/content/56673)

它将使您能够连接到相机并应用属性。这是关于如何解析相机的 sn-p。

Class clsPlayer = Class.forName("com.unity3d.player.UnityPlayer");
    Field fCurrentActivity = clsPlayer.getDeclaredField("currentActivity");
    fCurrentActivity.setAccessible(true);
    com.unity3d.player.UnityPlayerActivity currentActivity = (com.unity3d.player.UnityPlayerActivity)fCurrentActivity.get(null);
    ret.playerActivity = currentActivity;

    Field fPlayer = currentActivity.getClass().getDeclaredField("mUnityPlayer");
    fPlayer.setAccessible(true);
    com.unity3d.player.UnityPlayer player = (com.unity3d.player.UnityPlayer)fPlayer.get(currentActivity);
    ret.player = player;

    Field f = player.getClass().getDeclaredField("y");
    f.setAccessible(true);
    java.util.ArrayList cameraArrays = (java.util.ArrayList)f.get( player );
    int sz = cameraArrays.size();

然后,您将不得不更改 Android 插件中的参数,例如(取自 Camera Capture Kit)

Camera.Parameters params = ret.camera.getParameters();

    String flat = params.flatten();
    String iso_keyword=null;
    if(flat.contains("iso-values")) {
        iso_keyword="iso";
    } else if(flat.contains("iso-mode-values")) {
        iso_keyword="iso";
    } else if(flat.contains("iso-speed-values")) {
        iso_keyword="iso-speed";
    } else if(flat.contains("nv-picture-iso-values")) {
        iso_keyword="nv-picture-iso";
    }
    if( iso_keyword == null ) {
        Log.d("Unity", "CameraCaptureKit: It looks like there was no support for iso on the device." ); 
        return;
    }

    String strSupportedIsoValues = UnityCamera_GetSupportedISOValues();
    ArrayList<String> supportedIsoValues = new ArrayList<String>(Arrays.asList(strSupportedIsoValues.split(",") ));
    //ArrayList<String> supportedIsoValues = Arrays.asList( strSupportedIsoValues.split(",") );
    boolean contains = false;
    for( String isoValue : supportedIsoValues ) {
        if(isoValue.contains(newValue)) { 
            contains = true; 
            break; 
        }
    }
    if( contains == false ) {
        Log.d("Unity", "CameraCaptureKit: failed to set ISO, the value " + newValue + " is not supported. ( " + strSupportedIsoValues + " )" );
        return;
    }

    // update the camera.
    params.set( iso_keyword, newValue );
    ret.camera.setParameters(params);

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2018-03-11
    • 2019-05-01
    相关资源
    最近更新 更多