Example #1
0
        private void TestToIsoTemplate(IEnumerable <MinutiaRecord> minutae, string isoTemplateHex)
        {
            // Get the IsoTemplate
            byte[] template = IsoTemplateHelper.ToIsoTemplate(minutae);
            // Convert the IsoTemplate back to a list of minutia (loss of data in casting)
            IEnumerable <MinutiaRecord> convert_minutae = IsoTemplateHelper.ToMinutae(template);

            // Convert it to Hex for comparison
            string templateHex = BitConverter.ToString(template);

            templateHex = templateHex.Replace("-", String.Empty);

            // Assertions
            CollectionAssert.AreEqual(IsoTemplateHelper.ToByteArray(isoTemplateHex), template);
            Assert.AreEqual(minutae.Count(), convert_minutae.Count());
            for (int i = 0; i < convert_minutae.Count(); i++)
            {
                MinutiaRecord real_minutia      = minutae.ElementAt(i);
                MinutiaRecord converted_minutia = convert_minutae.ElementAt(i);
                Assert.AreEqual((int)real_minutia.Position.X, converted_minutia.Position.X);
                Assert.AreEqual((int)real_minutia.Position.Y, converted_minutia.Position.Y);
                // y(x,a) = ax - floor(ax)
                // max(y(x,a)) = 1, min(y(x,a)) = 0
                // e(x,a) = x - x_hat =  1/a * floor(ax) = 1/a * y(x,a)
                // Thus max(e(x,a)) = 1/a, min(e(x,a)) = 0
                Assert.IsTrue(real_minutia.Angle - converted_minutia.Angle < 1.0 / (256 / 360));
            }
        }
Example #2
0
            public static CaptureInfo ToCaptureInfo(XElement captureEl)
            {
                XElement imageLocationEl = captureEl.Element(ELEMENT_IMAGE_LOCATION);
                XElement dbIdEl          = captureEl.Element(ELEMENT_DB_ID);
                XElement templateEl      = captureEl.Element(ELEMENT_TEMPLATE);

                // Assert xml structure is as expected
                CheckElementNotNull(imageLocationEl, ELEMENT_IMAGE_LOCATION);
                CheckElementNotNull(dbIdEl, ELEMENT_DB_ID);
                CheckElementNotNull(templateEl, ELEMENT_TEMPLATE);

                // Get info from elements
                Uri  imageLocation;
                bool isUriParsed = Uri.TryCreate(imageLocationEl.Value, UriKind.Absolute, out imageLocation);

                if (!isUriParsed)
                {
                    throw new SimTemplateException(
                              String.Format("Failed to parse image URL string ({0}) to Uri", imageLocationEl.Value));
                }
                long dbId;
                bool isIdParsed = long.TryParse(dbIdEl.Value, out dbId);

                if (!isIdParsed)
                {
                    throw new SimTemplateException(
                              String.Format("Failed to parse capture ID string ({0}) to long", dbIdEl.Value));
                }
                byte[] templateData = null;
                if (!String.IsNullOrEmpty(templateEl.Value))
                {
                    templateData = IsoTemplateHelper.ToByteArray(templateEl.Value);
                }
                byte[] imageData;

                // Get image file from url
                using (WebClient webClient = new WebClient())
                {
                    imageData = webClient.DownloadData(imageLocation);
                }

                return(new CaptureInfo(dbId, imageData, templateData));
            }