public static ProjectorCameraEnsemble ReadCalibration(Stream stream)
        {
            ProjectorCameraEnsemble room = null;

            try
            {
                var knownTypeList = new List <Type>();
                //knownTypeList.Add(typeof(Matrix));
                knownTypeList.Add(typeof(ProjectorCameraEnsemble.Camera.Kinect2Calibration));
                var serializer = new DataContractSerializer(typeof(ProjectorCameraEnsemble), knownTypeList);
                room = (ProjectorCameraEnsemble)serializer.ReadObject(stream);
                stream.Close();

                //var serializer = new XmlSerializer(typeof(ProjectorCameraEnsemble));
                ////var fileStream = new FileStream(filename, FileMode.Open);
                //room = (ProjectorCameraEnsemble)serializer.Deserialize(stream);
                //stream.Close();
            }
            catch (Exception e)
            {
                Debug.LogError("Error loading configuration file: " + e.Message);
            }

            return(room);
        }
示例#2
0
 public void LoadAsset()
 {
     if (calibration != null)
     {
         ensemble = ProjectorCameraEnsemble.ReadCalibration(calibration.text);
     }
     loaded = true;
 }
示例#3
0
        internal void LoadCalibrationData()
        {
            cam        = this.GetComponent <Camera>();
            projConfig = null;
            if (hasCalibration)
            {
                ProjectorCameraEnsemble ensembleConfig = calibrationData.GetEnsemble();
                foreach (ProjectorCameraEnsemble.Projector pc in ensembleConfig.projectors)
                {
                    if (pc.name == nameInConfiguration)
                    {
                        projConfig = pc;
                    }
                }
            }
            else
            {
                projConfig = null;
            }


            if (projConfig != null)
            {
                if (displayIndex < 0)
                {
                    displayIndex = projConfig.displayIndex;
                }
                //Debug.Log("Projective Rendering - Loading projector calibration information.");
                imageWidth  = projConfig.width;
                imageHeight = projConfig.height;

                //// used by shadow etc...
                //// this is the vertical field of view - fy
                cam.aspect = (float)imageWidth / imageHeight;

                cam.fieldOfView = 2.0f * Mathf.Atan(imageHeight * 0.5f / (float)projConfig.cameraMatrix[1, 1]) * Mathf.Rad2Deg;

                Matrix4x4 opencvProjMat = GetProjectionMatrix(projConfig.cameraMatrix, cam.nearClipPlane, cam.farClipPlane);
                cam.projectionMatrix = UnityUtilities.ConvertRHtoLH(opencvProjMat);

                //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();

                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);
                this.transform.localPosition = worldToLocal.ExtractTranslation();
                this.transform.localRotation = worldToLocal.ExtractRotation();
            }
            else
            {
                Debug.Log("Projective Rendering - Using default camera calibration information.");
                lensDist = new Vector4();
            }
        }
        public static ProjectorCameraEnsemble Load(string filename)
        {
            ProjectorCameraEnsemble room = null;

            try
            {
                /*
                 * var serializer = new XmlSerializer(typeof(ProjectorCameraEnsemble));
                 * var fileStream = new FileStream(filename, FileMode.Open);
                 * room = (ProjectorCameraEnsemble)serializer.Deserialize(fileStream);
                 * fileStream.Close();
                 */

                room = ReadCalibration(new FileStream(filename, FileMode.Open));

                // testing
                {
                    /*
                     * var outputFilestream = new FileStream(filename + ".out.xml", FileMode.Create);
                     *                  serializer.WriteObject(outputFilestream, room);
                     *                  outputFilestream.Close();
                     */

                    /*var outKnownTypeList = new List<Type>();
                    *  knownTypeList.Add(typeof(Kinect2Calibration));
                    *  var outSerializer = new DataContractSerializer(typeof(ProjectorCameraEnsemble), knownTypeList);
                    *  var settings = new XmlWriterSettings { Indent = true };
                    *  using (var writer = XmlWriter.Create(filename + ".out.xml", settings))
                    *   outSerializer.WriteObject(writer, room);*/
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Error loading configuration file: " + e.Message);
            }

            return(room);
        }