// coordinates server discovery and XML setup static void DiscoverServers() { cout.VerbosePrint("Finding Kinect and projector servers..."); var findKServers = Task <Collection <EndpointDiscoveryMetadata> > .Factory.StartNew(DiscoverCameras); var findPServers = Task <Collection <EndpointDiscoveryMetadata> > .Factory.StartNew(DiscoverProjectors); var kServers = findKServers.Result; var pServers = findPServers.Result; ensemble = new ProjectorCameraEnsemble(pServers.Count, kServers.Count); for (int i = 0; i < kServers.Count; ++i) { ensemble.cameras[i].name = i.ToString(); ensemble.cameras[i].hostNameOrAddress = kServers[i].Address.Uri.DnsSafeHost; } for (int i = 0; i < pServers.Count; ++i) { ensemble.projectors[i].name = i.ToString(); ensemble.projectors[i].hostNameOrAddress = pServers[i].Address.Uri.DnsSafeHost; ensemble.projectors[i].displayIndex = 1; // Projectors are indexed 1 by default } cout.VerbosePrint("Server search complete."); }
protected override void Initialize() { // Modify the title of the window Window.Title = "HolographicStudio"; Window.AllowUserResizing = false; // Manually position to fullscreen so we can alt-tab to Visual Studio while debugging var window = Window.NativeWindow as System.Windows.Forms.Form; if (window != null) { window.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; window.Location = new System.Drawing.Point(0, 0); window.Size = new System.Drawing.Size(1920, 1080); } // load ensemble.xml string path = HolographicStudio.Utils.Configuration.EnsembleConfigurationFile; string directory = Path.GetDirectoryName(path); try { _ensemble = RoomAliveToolkit.ProjectorCameraEnsemble.FromFile(path); // Create geometry renderers for each 3D camera foreach (var camera in _ensemble.cameras) { string colorImagePath = Path.Combine(directory, string.Format("camera{0}", camera.name), "color.tiff"); string depthImagePath = Path.Combine(directory, string.Format("camera{0}", camera.name), "mean.tiff"); _geometryRenderers.Add(new RoomAliveGeometryRenderer(this, camera, colorImagePath, depthImagePath)); } } catch (FileNotFoundException ex) { Console.WriteLine("Could not find calibration file."); } _tweakableManager.AddTweakable(new FloatTweakable("Clip Radius", new PropertyInvoker <float>("Radius", this), 0.01f, 10f, 0.01f)); _tweakableManager.AddTweakable(new FloatTweakable("Clip CenterX", new PropertyInvoker <float>("CenterX", this), -10f, 10f, 0.01f)); _tweakableManager.AddTweakable(new FloatTweakable("Clip CenterY", new PropertyInvoker <float>("CenterY", this), -10f, 10f, 0.01f)); _tweakableManager.AddTweakable(new FloatTweakable("Clip CenterZ", new PropertyInvoker <float>("CenterZ", this), 0f, 10f, 0.01f)); _tweakableManager.AddTweakable(new FloatTweakable("Clip Floor", new PropertyInvoker <float>("Floor", this), -5f, 5f, 0.01f)); _tweakableManager.AddTweakable(new FloatTweakable("Clip Ceiling", new PropertyInvoker <float>("Ceiling", this), -5f, 5f, 0.01f)); _tweakableManager.AddTweakable(new BooleanTweakable("Apply Hologram Effect", new PropertyInvoker <bool>("HologramEnabled", this))); for (int i = 0; i < _ensemble.cameras.Count; i++) { _tweakableManager.AddTweakable(new BooleanTweakable(string.Format("LiveDepth{0}", i), new PropertyInvoker <bool>("LiveDepth", _geometryRenderers[i]))); _tweakableManager.AddTweakable(new BooleanTweakable(string.Format("LiveColor{0}", i), new PropertyInvoker <bool>("LiveColor", _geometryRenderers[i]))); _tweakableManager.AddTweakable(new BooleanTweakable(string.Format("FilterDepth{0}", i), new PropertyInvoker <bool>("FilterDepth", _geometryRenderers[i]))); _tweakableManager.AddTweakable(new FloatTweakable(string.Format("SpatialSigma{0}", i), new PropertyInvoker <float>("SpatialSigma", _geometryRenderers[i]), 0.1f, 10f, 0.1f)); _tweakableManager.AddTweakable(new FloatTweakable(string.Format("IntensitySigma{0}", i), new PropertyInvoker <float>("IntensitySigma", _geometryRenderers[i]), 1f, 1000f, 1f)); _tweakableManager.AddTweakable(new FloatTweakable(string.Format("DepthThreshold{0}", i), new PropertyInvoker <float>("DepthThreshold", _geometryRenderers[i]), 0f, 1f, 0.01f)); } _tweakableManager.AddTweakable(new BooleanTweakable("Animate", new PropertyInvoker <bool>("Animate", this))); base.Initialize(); }
// loades ensemble configuration from XML file static bool LoadXML() { try { using (var fileStream = new FileStream(XMLfilename, FileMode.Open)) { var knownTypeList = new List <Type>(); knownTypeList.Add(typeof(Kinect2Calibration)); var serializer = new DataContractSerializer(typeof(ProjectorCameraEnsemble), knownTypeList); ensemble = (ProjectorCameraEnsemble)serializer.ReadObject(fileStream); } return(true); } catch (FileNotFoundException) { cout.Print("Could not find XML configuration file."); } catch (Exception e) { cout.Print("Could not open configuration file."); cout.DebugPrint(e.Message); } return(false); }
// void OnRenderImage (RenderTexture source, RenderTexture destination) // { // if(flipCameraX && camFlipMat) // { // Graphics.Blit(source, destination, camFlipMat); // } // } private void LoadCalibrationData() { projConfig = null; cam = GetComponent <Camera>(); if (!cam) { Debug.LogError("Please add the ProjectorCamera-component to a camera in the scene."); return; } if (calibrationXml) { ensemble = ProjectorCameraEnsemble.ReadCalibration(calibrationXml.text); foreach (ProjectorCameraEnsemble.Projector pc in ensemble.projectors) { if (pc.name == projNameInConfig) { projConfig = pc; } } } else { projConfig = null; } if (projConfig != null) { if (displayIndex < 0) { displayIndex = projConfig.displayIndex; Debug.Log("ProjCam target display: " + displayIndex); if (useProjectorDisplay && displayIndex >= 0) { //#if !UNITY_EDITOR cam.targetDisplay = displayIndex; //#endif } } //Debug.Log("Projective Rendering - Loading projector calibration information."); imageWidth = projConfig.width; imageHeight = projConfig.height; if (imageWidth > 0 && imageHeight > 0 && projConfig.cameraMatrix != null) { cam.aspect = (float)imageWidth / imageHeight; // this is the vertical field of view - fy float fieldOfViewRad = 2.0f * (float)System.Math.Atan((((double)(imageHeight)) / 2.0) / projConfig.cameraMatrix[1, 1]); float fieldOfViewDeg = fieldOfViewRad / 3.14159265359f * 180.0f; cam.fieldOfView = fieldOfViewDeg; Debug.Log("ProjCam FOV: " + fieldOfViewDeg); Matrix4x4 opencvProjMat = GetProjectionMatrix(projConfig.cameraMatrix, cam.nearClipPlane, cam.farClipPlane); cam.projectionMatrix = UnityUtilities.ConvertRHtoLH(opencvProjMat); } if (projConfig.lensDistortion != null) { //var irCoef = projConfig.lensDistortion.AsFloatArray(); //! jolaur -- looks like this is not being used and is now 2 elements instead of four in the new xml format //! lensDist = new Vector4(irCoef[0], irCoef[1], irCoef[2], irCoef[3]); //lensDist = new Vector4(); } if (projConfig.pose != null) { Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose); worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal); KinectManager kinectManager = KinectManager.Instance; this.transform.localPosition = worldToLocal.ExtractTranslation() + new Vector3(0f, kinectManager.sensorHeight, 0f); this.transform.localRotation = worldToLocal.ExtractRotation(); Debug.Log("ProjCam position: " + transform.localPosition + ", rotation: " + transform.localRotation.eulerAngles); } } else { Debug.LogError("Make sure the 'Calibration Xml' && 'Proj name in config'-settings are correct."); //lensDist = new Vector4(); } }