// saves the adjusted camera pose to multi-cam config public void SaveMultiCamAdjustedPose() { // adjust the sensor rotation for (int i = 1; i < numSensors; i++) { Vector3 adjustedRot = sensorRotTransform[i] + sensorRotAdjust[i]; multiCamPose.camPose[i].rotation = Quaternion.Euler(adjustedRot).eulerAngles; Vector3 adjustedPos = sensorPosTransform[i] + sensorPosAdjust[i]; multiCamPose.camPose[i].position = adjustedPos; } // save the multi-camera config string multiCamJson = JsonUtility.ToJson(multiCamPose, true); KinectInterop.SaveTextFile(KinectInterop.MULTI_CAM_CONFIG_FILE_NAME, multiCamJson); if (camInfoText != null) { camInfoText.text = "Saved the adjusted multi-camera configuration."; } }
// periodically estimates the camera poses private IEnumerator EstimateCameraPoses() { while (!bStopCoroutine) { bool bSingleUser = CheckForSingleUser(); int numSamples = 0; if (kinectManager && kinectManager.IsInitialized() && numSensors > 1 && bSingleUser) { for (int i = 0; i < numSensors; i++) { KinectInterop.SensorData sensorData = kinectManager.GetSensorData(i); if (i == 0) { // first camera Transform sensorTrans = kinectManager.GetSensorTransform(0); refCameraPos = sensorTrans.position; refCameraRot = sensorTrans.rotation; // src camera matrix srcCameraMatrix = Matrix4x4.TRS(refCameraPos, refCameraRot, Vector3.one); // src user pose if (GetUserPose(sensorData, playerIndex, ref refUserPos, ref refUserRot)) { // src user matrix srcUserMatrix = Matrix4x4.TRS(refUserPos, refUserRot, Vector3.one); // save current camera pose SaveSensorPose(i, refCameraPos, refCameraRot); } } else { // other camera if (GetUserPose(sensorData, playerIndex, ref userBodyPos, ref userBodyRot)) { // dst user matrix Matrix4x4 dstUserMatrix = Matrix4x4.TRS(userBodyPos, userBodyRot, Vector3.one); // dst camera matrix Matrix4x4 dstCameraMatrix = srcCameraMatrix * srcUserMatrix * dstUserMatrix.inverse; // est camera position & rotation Vector3 estCameraPos = dstCameraMatrix.GetColumn(3); Quaternion estCameraRot = dstCameraMatrix.rotation; // save current camera pose SaveSensorPose(i, estCameraPos, estCameraRot); } } } System.DateTime dtNow = System.DateTime.UtcNow; multiCamPose.estimatedAtTime = dtNow.Ticks; multiCamPose.estimatedDateTime = dtNow.ToShortDateString() + " " + dtNow.ToShortTimeString(); // show progress numSamples = GetNumberOfSamples(); float fProgress = (float)numSamples / (float)MAX_SAVED_POSES; if (progressBar != null) { progressBar.size = fProgress; } if (progressText != null) { progressText.text = string.Format("{0:F0}%", fProgress * 100f); } // show sensor info ShowCamPosesInfo(fProgress); } if (numSensors > 1 && !bSingleUser) { if (camInfoText != null) { camInfoText.text = "Only one person should stay visible to all sensors until the calibration completes."; } } if (numSamples < MAX_SAVED_POSES) { // wait between samples yield return(new WaitForSeconds(TIME_BETWEEN_PROBES)); } else { // save the multi-camera config string multiCamJson = JsonUtility.ToJson(multiCamPose, true); KinectInterop.SaveTextFile(KinectInterop.MULTI_CAM_CONFIG_FILE_NAME, multiCamJson); if (camInfoText != null) { camInfoText.text = "Saved multi-camera configuration. Calibration finished!"; } yield break; } } }
// takes multiple samples and auto-calibrates the cameras private IEnumerator AutoCalibrateCameras() { if (countdown != null && countdown.Length > 0) { for (int i = 0; i < countdown.Length; i++) { if (countdown[i]) { countdown[i].gameObject.SetActive(true); } yield return(new WaitForSeconds(1f)); if (countdown[i]) { countdown[i].gameObject.SetActive(false); } } } else { // wait for 3 seconds yield return(new WaitForSeconds(3f)); } while (!bStopCoroutine) { bool bSingleUser = CheckForSingleUser(false); int numSamples = 0; float lastUserTime = CheckForSameUserTime(); //Debug.Log("SingleUser: "******", LastUserTime: " + lastUserTime + ", ProcUserTime: " + lastProcUserTime); if (kinectManager && kinectManager.IsInitialized() && numSensors > 1 && // bSingleUser && lastUserTime != 0f && lastUserTime != lastProcUserTime) { lastProcUserTime = lastUserTime; for (int i = 0; i < numSensors; i++) { KinectInterop.SensorData sensorData = kinectManager.GetSensorData(i); if (i == 0) { SaveSensorPose(i, refCameraPos, refCameraRot, ref userBodyPose[i]); } else { GetEstCameraPose(i, out Vector3 estCamPos, out Quaternion estCamRot); SaveSensorPose(i, estCamPos, estCamRot, ref userBodyPose[i]); } } System.DateTime dtNow = System.DateTime.UtcNow; multiCamPose.estimatedAtTime = dtNow.Ticks; multiCamPose.estimatedDateTime = dtNow.ToShortDateString() + " " + dtNow.ToShortTimeString(); // show progress numSamples = GetNumberOfSamples(); float fProgress = (float)numSamples / (float)maxSavedSamples; if (progressBar != null) { progressBar.size = fProgress; } if (progressText != null) { progressText.text = string.Format("{0:F0}%", fProgress * 100f); } // show sensor info ShowCamPosesInfo(fProgress); } if (numSensors > 1 && !bSingleUser) { if (camInfoText != null) { camInfoText.text = "Only one person should stay visible to all sensors until the calibration completes."; } } if (numSamples < maxSavedSamples) { // wait between samples yield return(new WaitForSeconds(TIME_BETWEEN_PROBES)); } else { // save the multi-camera config string multiCamJson = JsonUtility.ToJson(multiCamPose, true); KinectInterop.SaveTextFile(KinectInterop.MULTI_CAM_CONFIG_FILE_NAME, multiCamJson); if (camInfoText != null) { camInfoText.text = "Saved multi-camera configuration. Calibration finished!\nFeel free to manually adjust the sensor poses, if needed.\nUse Alt+mouse drag to orbit around the subject."; } // show the manual adjustment panel ShowUpdatePanel(); yield break; } } }