Пример #1
0
        public EnsembleData(string ensembleFile)
        {
            XElement root = XElement.Load(ensembleFile);

            // Deserialize ensemble file
            try {
                XNamespace ns = root.Name.Namespace;
                name    = root.Element(ns + "name").Value;
                cameras =
                    (from camera in root.Descendants(ns + "ProjectorCameraEnsemble.Camera")
                     select new CameraData {
                    calibration = MakeCalibration(camera, ns),
                    hostNameOrAddress = camera.Element(ns + "hostNameOrAddress").Value,
                    name = camera.Element(ns + "name").Value,
                    pose = CalibrationMatrix.ToMatrix4x4(camera.Element(ns + "pose"))
                }).ToList();
                projectors =
                    (from projector in root.Descendants(ns + "ProjectorCameraEnsemble.Projector")
                     select new ProjectorData {
                    cameraMatrix = CalibrationMatrix.ToMatrix4x4(projector.Element(ns + "cameraMatrix")),
                    displayIndex = Convert.ToInt32(projector.Element(ns + "displayIndex").Value),
                    width = Convert.ToInt32(projector.Element(ns + "width").Value),
                    height = Convert.ToInt32(projector.Element(ns + "height").Value),
                    hostNameOrAddress = projector.Element(ns + "hostNameOrAddress").Value,
                    lensDistortion = CalibrationMatrix.ToMatrix4x4(projector.Element(ns + "lensDistortion")),
                    lockIntrinsics = Convert.ToBoolean(projector.Element(ns + "lockIntrinsics").Value),
                    name = projector.Element(ns + "name").Value,
                    pose = CalibrationMatrix.ToMatrix4x4(projector.Element(ns + "pose"))
                }).ToList();
            } catch (NullReferenceException) {
                throw new NullReferenceException("File incorrect format.");
            }
        }
Пример #2
0
 public static void CalibrateTouchscreen(VirtualCanvas canvas)
 {
     try {
         //var sd = new SDCardReader();
         //sd.Initialize(SPI.SPI_module.SPI1,Pins.GPIO_PIN_D10);
         var calibrationDataFilename = @"SD\TouchscreenCalibration.bin";
         // If the touchscreen calibration data was previously retrieved from the display module and was stored to an SD card,
         // the calibration data can be sent to the display module instead of calling TouchscreenCalibration() before using
         // the touchscreen for the first time.
         if (File.Exists(calibrationDataFilename))
         {
             using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Open)) {
                 var context = new BasicTypeDeSerializerContext(calibrationDataFile);
                 var matrix  = new CalibrationMatrix();
                 matrix.Get(context);
                 canvas.SetTouchscreenCalibrationMatrix(matrix);
             }
         }
         else
         {
             // No pre-existing calibration data, create it...
             using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Create)) {
                 var matrix  = canvas.GetTouchscreenCalibrationMatrix();
                 var context = new BasicTypeSerializerContext(calibrationDataFile);
                 matrix.Put(context);
             }
         }
         //sd.Dispose();
     } catch (Exception) {
         Debug.Print("SD Card or file I/O error: manual calibration required.");
         canvas.TouchscreenCalibration();
     }
 }
Пример #3
0
        public static void CalibrateTouchscreen(VirtualCanvas canvas)
        {
            var sd = new SDCardReader();

            try {
                sd.Initialize(SDSocket);
                var calibrationDataFilename = @"SD\TouchscreenCalibration.bin";
                if (File.Exists(calibrationDataFilename))
                {
                    using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Open)) {
                        var context = new BasicTypeDeSerializerContext(calibrationDataFile);
                        var matrix  = new CalibrationMatrix();
                        matrix.Get(context);
                        canvas.SetTouchscreenCalibrationMatrix(matrix);
                    }
                }
                else
                {
                    using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Create)) {
                        var matrix  = canvas.GetTouchscreenCalibrationMatrix();
                        var context = new BasicTypeSerializerContext(calibrationDataFile);
                        matrix.Put(context);
                    }
                }
            } catch (Exception e) {
                Debug.Print(e.Message);
                Debug.Print("SD Card or file I/O error: manual calibration required.");
                canvas.TouchscreenCalibration();
            }
            sd.Dispose();
        }
Пример #4
0
        CameraCalibration MakeCalibration(XElement cameraNode, XNamespace ns)
        {
            XElement calibration = cameraNode.Element(ns + "calibration");

            return(new CameraCalibration(CalibrationMatrix.ToMatrix4x4(calibration.Element(ns + "colorCameraMatrix")),
                                         CalibrationMatrix.ToMatrix4x4(calibration.Element(ns + "colorLensDistortion")),
                                         CalibrationMatrix.ToMatrix4x4(calibration.Element(ns + "depthCameraMatrix")),
                                         CalibrationMatrix.ToMatrix4x4(calibration.Element(ns + "depthLensDistortion")),
                                         CalibrationMatrix.ToMatrix4x4(calibration.Element(ns + "depthToColorTransform"))));
        }
Пример #5
0
 public CalibrationMatrix GetTouchscreenCalibrationMatrix() {
     BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenGetCalibrationMatrix);
     Execute();
     Receive();
     TouchScreenDataType eventType = (TouchScreenDataType)BasicTypeDeSerializer.Get(ReceiveContext);
     if (eventType != TouchScreenDataType.CalibrationMatrix) {
         throw new ApplicationException("eventType");
     }
     var matrix = new CalibrationMatrix();
     matrix.Get(ReceiveContext);
     return matrix;
 }
Пример #6
0
 /// <summary>
 /// Updates the calibration matrix using the 6 Affine Transformation parameters
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <param name="c"></param>
 /// <param name="d"></param>
 /// <param name="e"></param>
 /// <param name="f"></param>
 public void SetCalibration(double a, double b, double c, double d, double e, double f)
 {
     CalibrationMatrix = new CalibrationMatrix(DateTime.Now, a, b, c, d, e, f);
 }
Пример #7
0
        /// <summary>
        /// Updates the calibration matrix using the 6 Affine Transformation parameters
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="d"></param>
        /// <param name="e"></param>
        /// <param name="f"></param>
        public void SetCalibration(double a, double b, double c, double d, double e, double f)
        {
			CalibrationMatrix = new CalibrationMatrix(DateTime.Now, a, b, c, d, e, f);
        }
Пример #8
0
 public void SetTouchscreenCalibrationMatrix(CalibrationMatrix matrix)
 {
     BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenSetCalibrationMatrix);
     matrix.Put(SendContext);
     Execute();
 }