/// <summary> /// Fill the projection matrix with the parameters of the ZED, needs to be called only once. This projection matrix is off center. /// </summary> /// <param name="zFar"></param> /// <param name="zNear"></param> public void FillProjectionMatrix(float zFar = 500, float zNear = 0.2f) { CalibrationParameters parameters = GetCameraInformation().calibParameters; float fovx = parameters.leftCam.hFOV * Mathf.Deg2Rad; float fovy = parameters.leftCam.vFOV * Mathf.Deg2Rad; projection[0, 0] = 1.0f / Mathf.Tan(fovx * 0.5f); projection[0, 1] = 0; projection[0, 2] = 2 * ((ImageWidth - 1 * parameters.leftCam.cx) / ImageWidth) - 1.0f; projection[0, 3] = 0; projection[1, 0] = 0; projection[1, 1] = 1.0f / Mathf.Tan(fovy * 0.5f); projection[1, 2] = -(2 * ((ImageHeight - 1 * parameters.leftCam.cy) / ImageHeight) - 1.0f); projection[1, 3] = 0; projection[2, 0] = 0; projection[2, 1] = 0; projection[2, 2] = -(zFar + zNear) / (zFar - zNear); projection[2, 3] = -(2.0f * zFar * zNear) / (zFar - zNear); projection[3, 0] = 0; projection[3, 1] = 0; projection[3, 2] = -1; projection[3, 3] = 0.0f; }
void ZEDReady() { Vector2 scaleFromZED; halfBaselineOffset.x = zedCamera.Baseline / 2.0f; float perception_distance = 1.0f; float zed2eye_distance = 0.1f; hasVRDevice = UnityEngine.XR.XRDevice.isPresent; if (hasVRDevice) { sl.CalibrationParameters parameters = zedCamera.CalibrationParametersRectified; scaleFromZED = ComputeSizePlaneWithGamma(new sl.Resolution((uint)zedCamera.ImageWidth, (uint)zedCamera.ImageHeight), perception_distance, zed2eye_distance, offset.z, ComputeFocal(new sl.Resolution((uint)UnityEngine.XR.XRSettings.eyeTextureWidth, (uint)UnityEngine.XR.XRSettings.eyeTextureHeight)),//571.677612f, parameters.leftCam.fx); scale(quadLeft.gameObject, finalLeftEye, scaleFromZED); scale(quadRight.gameObject, finalRightEye, scaleFromZED); ready = false; } zedReady = true; }
void OnGUI() { FirstInit(); defaultColor = GUI.color; if (zedCamera != null && zedCamera.IsCameraReady) { GUI.color = Color.green; } else { GUI.color = Color.red; } GUILayout.BeginHorizontal(EditorStyles.helpBox); GUILayout.FlexibleSpace(); if (zedCamera != null && zedCamera.IsCameraReady) { style.normal.textColor = Color.black; GUILayout.Label("Online", style); } else { style.normal.textColor = Color.black; if (!launched) { GUILayout.Label("To access information, please launch your scene once", style); } else { GUILayout.Label("Offline", style); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUI.color = defaultColor; EditorGUI.BeginChangeCheck(); tab = GUILayout.Toolbar(tab, new string[] { "Camera Control", "Calibration" }); if (EditorGUI.EndChangeCheck()) { if (zedCamera != null && zedCamera.IsCameraReady) { parameters = zedCamera.GetCalibrationParameters(false); } } switch (tab) { case 0: CameraSettingsView(); break; case 1: CalibrationSettingsView(); break; default: CameraSettingsView(); break; } }
/// <summary> /// Updates values from the camera and redraws the elements. /// Called whenever the application play state changes. /// </summary> void Draw() { if (zedCamera != null && Application.isPlaying) { parameters = zedCamera.GetCalibrationParameters(false); zed_serial_number = zedCamera.GetZEDSerialNumber(); zed_fw_version = zedCamera.GetZEDFirmwareVersion(); zed_model = zedCamera.GetCameraModel(); } this.Repaint(); }
/// <summary> /// Initializes all the starting values, and gets current values from the ZED. /// </summary> void FirstInit() { if (!isInit) { zedCamera = sl.ZEDCamera.GetInstance(); EditorApplication.playmodeStateChanged += Draw; if (zedCamera != null && zedCamera.IsCameraReady) { isInit = true; if (!loaded) { if (resetWanted) { ResetValues(groupAuto); resetWanted = false; } zedCamera.RetrieveCameraSettings(); ZEDCameraSettingsManager.CameraSettings settings = zedCamera.GetCameraSettings(); groupAuto = zedCamera.GetExposureUpdateType(); whiteBalanceAuto = zedCamera.GetWhiteBalanceUpdateType(); hue = settings.Hue; brightness = settings.Brightness; contrast = settings.Contrast; saturation = settings.Saturation; exposure = settings.Exposure; gain = settings.Gain; zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.GAIN, gain, groupAuto); zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.EXPOSURE, exposure, groupAuto); zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.WHITEBALANCE, whiteBalance, whiteBalanceAuto); } else { LoadCameraSettings(); } parameters = zedCamera.GetCalibrationParameters(false); zed_serial_number = zedCamera.GetZEDSerialNumber(); zed_fw_version = zedCamera.GetZEDFirmwareVersion(); zed_model = zedCamera.GetCameraModel(); } } }
/// <summary> /// Refreshes data. Called by Unity when this window gets focus, such as when /// it's clicked on or alt-tabbed to. /// </summary> void OnFocus() { if (zedCamera != null && zedCamera.IsCameraReady) { parameters = zedCamera.GetCalibrationParameters(false); zed_serial_number = zedCamera.GetZEDSerialNumber(); zed_fw_version = zedCamera.GetZEDFirmwareVersion(); zed_model = zedCamera.GetCameraModel(); if (!loaded) { zedCamera.RetrieveCameraSettings(); UpdateValuesCameraSettings(); } } }
void ZEDReady() { Vector2 scaleFromZED; halfBaselineOffset.x = zedCamera.Baseline / 2.0f; float perception_distance = 1.0f; float zed2eye_distance = 0.1f; hasVRDevice = VRDevice.isPresent; if (hasVRDevice) { sl.CalibrationParameters parameters = zedCamera.CalibrationParametersRectified; scaleFromZED = ComputeSizePlaneWithGamma(new sl.Resolution((uint)zedCamera.ImageWidth, (uint)zedCamera.ImageHeight), perception_distance, zed2eye_distance, offset.z, ComputeFocal(new sl.Resolution((uint)UnityEngine.VR.VRSettings.eyeTextureWidth, (uint)UnityEngine.VR.VRSettings.eyeTextureHeight)),//571.677612f, parameters.leftCam.fx); scale(quadLeft.gameObject, finalLeftEye, scaleFromZED); scale(quadRight.gameObject, finalRightEye, scaleFromZED); ready = false; } // Only for vive... some image adjustment if (VRDevice.model.ToLower().Contains("vive")) { zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.CONTRAST, 3); zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.SATURATION, 3); } //Set eye layers to respective eyes. They were each set to Both during the loading screen to avoid one eye going blank at some rotations. finalLeftEye.stereoTargetEye = StereoTargetEyeMask.Left; finalRightEye.stereoTargetEye = StereoTargetEyeMask.Right; /// AR Passtrough is recommended in 1280x720 at 60, due to fov, fps, etc...; /// Set Warning for user if (zedCamera.ImageWidth != 1280 && zedCamera.ImageHeight != 720) { Debug.LogWarning("[ZED AR Passthrough] This resolution is not compatible with proper AR passthrough experience"); } zedReady = true; }
/// <summary> /// Called once the ZED is finished initializing. Subscribed to ZEDManager.OnZEDReady in OnEnable. /// Uses the newly-available ZED parameters to scale the final planes (quadLeft and quadRight) to appear /// properly in the currently-connected headset. /// </summary> void ZEDReady() { Vector2 scaleFromZED; halfBaselineOffset.x = zedCamera.Baseline / 2.0f; float perception_distance = 1.0f; float zed2eye_distance = 0.1f; //Estimating 10cm between your eye and physical location of the ZED Mini. hasVRDevice = VRDevice.isPresent; if (hasVRDevice) { sl.CalibrationParameters parameters = zedCamera.CalibrationParametersRectified; scaleFromZED = ComputeSizePlaneWithGamma(new sl.Resolution((uint)zedCamera.ImageWidth, (uint)zedCamera.ImageHeight), perception_distance, zed2eye_distance, offset.z, ComputeFocal(new sl.Resolution((uint)UnityEngine.VR.VRSettings.eyeTextureWidth, (uint)UnityEngine.VR.VRSettings.eyeTextureHeight)), parameters.leftCam.fx); scale(quadLeft.gameObject, scaleFromZED); scale(quadRight.gameObject, scaleFromZED); ready = false; } // If using Vive, change ZED's settings to compensate for different screen. if (VRDevice.model.ToLower().Contains("vive")) { zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.CONTRAST, 3); zedCamera.SetCameraSettings(sl.CAMERA_SETTINGS.SATURATION, 3); } //Set eye layers to respective eyes. They were each set to Both during the loading screen to avoid one eye going blank at some rotations. finalLeftEye.stereoTargetEye = StereoTargetEyeMask.Left; finalRightEye.stereoTargetEye = StereoTargetEyeMask.Right; /// AR Passtrough is recommended in 1280x720 at 60, due to FoV, FPS, etc. /// If not set to this resolution, warn the user. if (zedCamera.ImageWidth != 1280 && zedCamera.ImageHeight != 720) { Debug.LogWarning("[ZED AR Passthrough] This resolution is not ideal for a proper AR passthrough experience. Recommended resolution is 1280x720."); } zedReady = true; }
static void Init() { //Gets existing open window or, if none exists, makes a new one. ZEDCameraSettingsEditor window = (ZEDCameraSettingsEditor)EditorWindow.GetWindow(typeof(ZEDCameraSettingsEditor), false, "ZED Camera"); window.position = new Rect(window.position.x, window.position.y, 400, 400); style.normal.textColor = Color.red; style.fontSize = 15; style.margin.left = 5; parameters = new sl.CalibrationParameters(); window.Show(); Debug.Log("Camera S/N : " + zed_serial_number); Debug.Log("Camera Model : " + zed_model); Debug.Log("Camera FW : " + zed_fw_version); }
public void setCameraCalibration(sl.CalibrationParameters calib) { camera_calibration = calib; has_background_ready = false; }