Esempio n. 1
0
        public override TemplateBuilder Import(byte[] template)
        {
            TemplateBuilder builder = new TemplateBuilder();

            MemoryStream stream = new MemoryStream(template);
            BinaryReader reader = new BinaryReader(stream, Encoding.UTF8);

            // 4B magic
            for (int i = 0; i < Magic.Length; ++i)
            {
                AssertException.Check(reader.ReadByte() == Magic[i]);
            }

            // 1B version (current = 2)
            byte version = reader.ReadByte();

            AssertException.Check(version >= 1 && version <= 2);

            // 2B total length (including magic)
            reader.ReadInt16();

            if (version >= 2)
            {
                // 2B original DPI (since version 2)
                builder.OriginalDpi = IPAddress.NetworkToHostOrder(reader.ReadInt16());

                // 2B original width (since version 2)
                builder.OriginalWidth = IPAddress.NetworkToHostOrder(reader.ReadInt16());

                // 2B original height (since version 2)
                builder.OriginalHeight = IPAddress.NetworkToHostOrder(reader.ReadInt16());
            }

            // 2B minutia count
            int minutiaCount = IPAddress.NetworkToHostOrder(reader.ReadInt16());

            // N*6B minutia records
            for (int i = 0; i < minutiaCount; ++i)
            {
                TemplateBuilder.Minutia minutia = new TemplateBuilder.Minutia();

                //      2B position X
                minutia.Position.X = IPAddress.NetworkToHostOrder(reader.ReadInt16());

                //      2B position Y
                minutia.Position.Y = IPAddress.NetworkToHostOrder(reader.ReadInt16());

                //      1B direction
                minutia.Direction = reader.ReadByte();

                //      1B type
                minutia.Type = (TemplateBuilder.MinutiaType)reader.ReadByte();
                AssertException.Check(Enum.IsDefined(typeof(TemplateBuilder.MinutiaType), minutia.Type));

                builder.Minutiae.Add(minutia);
            }

            return(builder);
        }
Esempio n. 2
0
 public Minutia(TemplateBuilder.Minutia builderMinutia)
 {
     Position  = new PointS(builderMinutia.Position);
     Direction = builderMinutia.Direction;
     if (builderMinutia.Type == TemplateBuilder.MinutiaType.Extremidade)
     {
         Type = MinutiaType.Ending;
     }
     else
     {
         Type = MinutiaType.Bifurcation;
     }
 }
Esempio n. 3
0
 public TemplateBuilder.Minutia ToBuilderMinutia()
 {
     TemplateBuilder.Minutia builderMinutia = new TemplateBuilder.Minutia();
     builderMinutia.Position  = Position;
     builderMinutia.Direction = Direction;
     if (Type == MinutiaType.Ending)
     {
         builderMinutia.Type = TemplateBuilder.MinutiaType.Extremidade;
     }
     else
     {
         builderMinutia.Type = TemplateBuilder.MinutiaType.Bifurcação;
     }
     return(builderMinutia);
 }
Esempio n. 4
0
        public override TemplateBuilder Import(byte[] template)
        {
            TemplateBuilder builder = new TemplateBuilder();

            builder.OriginalDpi = 500;

            MemoryStream stream = new MemoryStream(template);
            BinaryReader reader = new BinaryReader(stream, Encoding.UTF8);

            // 4B magic "FMR\0"
            AssertException.Check(new String(reader.ReadChars(4)) == "FMR\0", "This is not an ISO template.");

            // 4B version (ignored, set to " 20\0"
            reader.ReadChars(4);

            // 4B total length (including header)
            AssertException.Check(IPAddress.NetworkToHostOrder(reader.ReadInt32()) == template.Length, "Invalid template length.");

            // 2B rubbish (zeroed)
            reader.ReadInt16();

            // 2B image size in pixels X
            builder.StandardDpiWidth = IPAddress.NetworkToHostOrder(reader.ReadInt16());

            // 2B image size in pixels Y
            builder.StandardDpiHeight = IPAddress.NetworkToHostOrder(reader.ReadInt16());

            // 2B rubbish (pixels per cm X, set to 196 = 500dpi)
            reader.ReadInt16();

            // 2B rubbish (pixels per cm Y, set to 196 = 500dpi)
            reader.ReadInt16();

            // 1B rubbish (number of fingerprints, set to 1)
            AssertException.Check(reader.ReadByte() == 1, "Only single-fingerprint ISO templates are supported.");

            // 1B rubbish (zeroed)
            reader.ReadByte();

            // 1B rubbish (finger position, zeroed)
            reader.ReadByte();

            // 1B rubbish (zeroed)
            reader.ReadByte();

            // 1B rubbish (fingerprint quality, set to 100)
            reader.ReadByte();

            // 1B minutia count
            int minutiaCount = reader.ReadByte();

            // N*6B minutiae
            for (int i = 0; i < minutiaCount; ++i)
            {
                TemplateBuilder.Minutia minutia = new TemplateBuilder.Minutia();

                //      2B minutia position X in pixels
                //          2b (upper) minutia type (01 ending, 10 bifurcation, 00 other (considered ending))
                ushort xPacked = (ushort)IPAddress.NetworkToHostOrder(reader.ReadInt16());
                minutia.Position.X = xPacked & (ushort)0x3fff;
                minutia.Type       = (xPacked & (ushort)0xc000) == 0x8000 ? TemplateBuilder.MinutiaType.Bifurcação : TemplateBuilder.MinutiaType.Extremidade;

                //      2B minutia position Y in pixels (upper 2b ignored, zeroed)
                minutia.Position.Y = builder.StandardDpiHeight - 1 - ((ushort)IPAddress.NetworkToHostOrder(reader.ReadInt16()) & (ushort)0x3fff);

                //      1B direction, compatible with SourceAFIS angles
                minutia.Direction = reader.ReadByte();

                //      1B quality (ignored, zeroed)
                reader.ReadByte();

                builder.Minutiae.Add(minutia);
            }

            // 2B rubbish (extra data length, zeroed)
            // N*1B rubbish (extra data)

            return(builder);
        }