public static DistortionParameters Import(string path, Size imageSize) { if (!File.Exists(path)) { return(null); } DistortionParameters parameters = null; try { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreProcessingInstructions = true; settings.IgnoreWhitespace = true; settings.CloseInput = true; using (XmlReader r = XmlReader.Create(path, settings)) { r.MoveToContent(); parameters = DistortionSerializer.Deserialize(r, imageSize); } } catch { log.ErrorFormat("Import of lens distortion parameters failed."); } return(parameters); }
public void ReadXml(XmlReader r, PointF scale, Size imageSize) { r.ReadStartElement(); while (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "CalibrationPlane": calibratorType = CalibratorType.Plane; calibrator = calibrationPlane; calibrationPlane.ReadPlaneXml(r, scale); ComputeCoordinateSystemGrid(); break; case "CalibrationLine": calibratorType = CalibratorType.Line; //calibrator = calibrationLine; calibrator = calibrationPlane; calibrationPlane.ReadLineXml(r, scale); //calibrationLine.ReadXml(r, scale); break; case "CalibrationDrawingId": Guid result; bool parsed = Guid.TryParse(r.ReadElementContentAsString(), out result); if (parsed) { calibrationDrawingId = result; } break; case "Unit": lengthUnit = (LengthUnit)Enum.Parse(typeof(LengthUnit), r.ReadElementContentAsString()); break; case "CameraCalibration": DistortionParameters parameters = DistortionSerializer.Deserialize(r, imageSize); distortionHelper.Initialize(parameters, imageSize); break; default: string unparsed = r.ReadOuterXml(); log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed); break; } } r.ReadEndElement(); AfterCalibrationChanged(); }