I'm trying to disable the camera auto-exposure. According to the docs here, https://developers.google.com/project-tango/apis/c/reference/group/config-params , it's possible to set the color_mode_auto, color_exp and color_iso values in the config.
I've tried setting values to the TangoConfig object straight after it is created in TangoApplication.cs, but I get a warning back saying these TangoConfig was unable to set the relevant keys (key string name taken directly from the docs above).
Is it possible to set these values in C#, and if so, where is the correct place to do it?
You might need to write a plugin that can set the iso value and exposure on the Unity camera instance. You can do that by taking an instance to the running camera's referance by some tricky hackery involving resolving the camera instance and then you should be able to inject the iso/exposure parameters.
An example of such plugin would be something like the Camera Capture Kit for Unity ( https://www.assetstore.unity3d.com/en/#!/content/56673 )
It will enable you to hook into the camera and apply properties. Here is a snippet on how the camera is resolved.
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();
You will then have to change the parameters inside an Android plugin , with something like this ( Taken from 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);
Cheers
来源:https://stackoverflow.com/questions/36483336/how-to-set-the-tango-camera-exposure-and-iso-parameters-from-c-unity