Exemplo n.º 1
0
        /// <summary>
        /// return an xml element containing camera calibration parameters
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="fov_degrees"></param>
        /// <param name="image_width"></param>
        /// <param name="image_height"></param>
        /// <param name="lens_distortion_curve"></param>
        /// <param name="centre_of_distortion_x"></param>
        /// <param name="centre_of_distortion_y"></param>
        /// <param name="rotation"></param>
        /// <param name="scale"></param>
        /// <param name="lens_distortion_image_filename"></param>
        /// <param name="curve_fit_image_filename"></param>
        /// <returns></returns>
        private static XmlElement getCameraXml(
            XmlDocument doc,
            float fov_degrees,
            int image_width, int image_height,
            polynomial lens_distortion_curve,
            double centre_of_distortion_x, double centre_of_distortion_y,
            double rotation, double scale,
            string lens_distortion_image_filename,
            string curve_fit_image_filename)
        {
            // make sure that floating points are saved in a standard format
            IFormatProvider format = new System.Globalization.CultureInfo("en-GB");

            string coefficients = "";
            if (lens_distortion_curve != null)
            {
                int degree = lens_distortion_curve.GetDegree();
                for (int i = 0; i <= degree; i++)
                {
                    coefficients += Convert.ToString(lens_distortion_curve.Coeff(i), format);
                    if (i < degree) coefficients += ",";
                }
            }
            else coefficients = "0,0,0";

            XmlElement elem = doc.CreateElement("Camera");
            doc.DocumentElement.AppendChild(elem);
            xml.AddComment(doc, elem, "Horizontal field of view of the camera in degrees");
            xml.AddTextElement(doc, elem, "FieldOfViewDegrees", Convert.ToString(fov_degrees, format));
            xml.AddComment(doc, elem, "Image dimensions in pixels");
            xml.AddTextElement(doc, elem, "ImageDimensions", Convert.ToString(image_width, format) + "," + Convert.ToString(image_height, format));
            xml.AddComment(doc, elem, "The centre of distortion in pixels");
            xml.AddTextElement(doc, elem, "CentreOfDistortion", Convert.ToString(centre_of_distortion_x, format) + "," + Convert.ToString(centre_of_distortion_y, format));
            xml.AddComment(doc, elem, "Polynomial coefficients used to describe the camera lens distortion");
            xml.AddTextElement(doc, elem, "DistortionCoefficients", coefficients);
            xml.AddComment(doc, elem, "Scaling factor");
            xml.AddTextElement(doc, elem, "Scale", Convert.ToString(scale));
            xml.AddComment(doc, elem, "Rotation of the image in degrees");
            xml.AddTextElement(doc, elem, "RotationDegrees", Convert.ToString(rotation / (float)Math.PI * 180.0f));
            xml.AddComment(doc, elem, "The minimum RMS error between the distortion curve and plotted points");
            xml.AddTextElement(doc, elem, "RMSerror", Convert.ToString(lens_distortion_curve.GetRMSerror(), format));
            xml.AddComment(doc, elem, "Image showing the lens distortion");
            xml.AddTextElement(doc, elem, "DistortionImageFilename", lens_distortion_image_filename);
            xml.AddComment(doc, elem, "Image showing the best fit curve");
            xml.AddTextElement(doc, elem, "CurveFitImageFilename", curve_fit_image_filename);

            return (elem);
        }
Exemplo n.º 2
0
        /// <summary>
        /// returns settings for either pan or tilt axis in Xml format
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="parent"></param>
        /// <param name="axis_name"></param>
        /// <param name="curve"></param>
        /// <param name="offset_x"></param>
        /// <param name="offset_y"></param>
        /// <returns></returns>
        private static XmlElement getPanTiltAxis(
            XmlDocument doc, XmlElement parent,
            string axis_name,
            polynomial curve, float offset_x, float offset_y)
        {
            // make sure that floating points are saved in a standard format
            IFormatProvider format = new System.Globalization.CultureInfo("en-GB");

            // pan/tilt mechanism parameters
            XmlElement nodeAxis = doc.CreateElement("Axis");
            xml.AddTextElement(doc, nodeAxis, "AxisName", axis_name);

            string coefficients = "";
            for (int i = 0; i <= curve.GetDegree(); i++)
            {
                coefficients += Convert.ToSingle(curve.Coeff(i), format);
                if (i < curve.GetDegree()) coefficients += ",";
            }
            xml.AddTextElement(doc, nodeAxis, "Coefficients", coefficients);
            xml.AddTextElement(doc, nodeAxis, "Offsets", Convert.ToString(offset_x, format) + "," + Convert.ToString(offset_y, format));
            parent.AppendChild(nodeAxis);
            return (nodeAxis);
        }