Using Source AFIS inside of ASP.NET Web API

distorsion

New Member
I'm currently going through the ASP.NET Web API mobile project template, which begins with a simple log-in and a few buttons including Home, Contacts and About. I have also been playing around with SourceAFIS, an open source fingerprint identification program, and from this I have developed the following code which will enroll a fingerprint:\[code\]namespace Enrolment{ class Program { // Inherit from Fingerprint in order to add Filename field [Serializable] class MyFingerprint : Fingerprint { public string Filename; } // Inherit from Person in order to add Name field [Serializable] class MyPerson : Person { public string Name; } // Initialize path to images static readonly string ImagePath = "images"; // Where fingerprint sample is stored // Shared AfisEngine instance (cannot be shared between different threads though) static AfisEngine Afis; // Take fingerprint image file and create Person object from the image static MyPerson Enroll(string filename, string name) { Console.WriteLine("Enrolling {0}...", name); // Initialize empty fingerprint object and set properties MyFingerprint fp = new MyFingerprint(); fp.Filename = filename; // Load image from the file BitmapImage image = new BitmapImage(new Uri(filename, UriKind.RelativeOrAbsolute)); fp.AsBitmapSource = image; // Above update of fp.AsBitmapSource initialized also raw image in fp.Image // Initialize empty person object and set its properties MyPerson person = new MyPerson(); person.Name = name; // Add fingerprint to the person person.Fingerprints.Add(fp); // Execute extraction in order to initialize fp.Template Afis.Extract(person); return person; } static void Main(string[] args) { // Initialize SourceAFIS Afis = new AfisEngine(); Console.WriteLine("Enrolment function\n"); // Enroll some people List<MyPerson> database = new List<MyPerson>(); BinaryFormatter formatter = new BinaryFormatter(); using (FileStream stream = File.OpenRead("database.dat")) database = (List<MyPerson>)formatter.Deserialize(stream); database.Add(Enroll(Path.Combine(ImagePath, "L_5thumb3.bmp"), "Bens Thumb")); // Enroll function Console.WriteLine("The database now has {0} entires...\n", database.Count); Console.WriteLine("Saving database..."); using (Stream stream = File.Open("database.dat", FileMode.Create)) formatter.Serialize(stream, database); Console.WriteLine("Press any key to continue..."); System.ConsoleKeyInfo KInfo1 = Console.ReadKey(true); return; } }}\[/code\]and the following code to Identify a fingerprint from the database:\[code\]namespace Identification{ class Program { // Inherit from Fingerprint in order to add Filename field [Serializable] class MyFingerprint : Fingerprint { public string Filename; } // Inherit from Person in order to add Name field [Serializable] class MyPerson : Person { public string Name; } // Initialize path to images static readonly string ImagePath = "images"; // Shared AfisEngine instance (cannot be shared between different threads though) static AfisEngine Afis; // Take fingerprint image file and create Person object from the image static MyPerson Enroll(string filename, string name) { //Console.WriteLine("Enrolling {0}...", name); // Initialize empty fingerprint object and set properties MyFingerprint fp = new MyFingerprint(); fp.Filename = filename; // Load image from the file BitmapImage image = new BitmapImage(new Uri(filename, UriKind.RelativeOrAbsolute)); fp.AsBitmapSource = image; // Above update of fp.AsBitmapSource initialized also raw image in fp.Image // Initialize empty person object and set its properties MyPerson person = new MyPerson(); person.Name = name; // Add fingerprint to the person person.Fingerprints.Add(fp); // Execute extraction in order to initialize fp.Template Afis.Extract(person); return person; } static void Main(string[] args) { // Initialize SourceAFIS Afis = new AfisEngine(); Console.WriteLine("Identifications function\n"); // Enroll some people List<MyPerson> database = new List<MyPerson>(); // Save the database to disk and load it back, just to try out the serialization BinaryFormatter formatter = new BinaryFormatter(); //Console.WriteLine("Loading database..."); using (FileStream stream = File.OpenRead("database.dat")) database = (List<MyPerson>)formatter.Deserialize(stream); // Enroll the fingerprint into the database, but it isn't stored, only to compare MyPerson probe = Enroll(Path.Combine(ImagePath, "L_5thumb4.bmp"), "Thumb Sample 2"); // Look up the probe using Threshold = 10 Afis.Threshold = 10; //Console.WriteLine("Identifying {0} in database of {1} persons...", probe.Name, database.Count); MyPerson match = Afis.Identify(probe, database).FirstOrDefault() as MyPerson; // Null result means that there is no candidate with similarity score above threshold if (match == null) { Console.WriteLine("No matching person found."); return; } // Print out any non-null result Console.WriteLine("{0} fingerprint matches registered person {1}", probe.Name, match.Name); // Compute similarity score float score = Afis.Verify(probe, match); Console.WriteLine("Similarity score between {0} and {1} = {2:F3}\n", probe.Name, match.Name, score); Console.WriteLine("Press any key to continue..."); System.ConsoleKeyInfo KInfo2 = Console.ReadKey(true); return; } }}\[/code\]From this I would basically like the edit the current Web API buttons to execute these functions and return the result. At the moment these two simply print the result to the terminal. I have done some searching and am struggling to find anything of relevance to help me out. This may be due to my current level of knowledge on the subject, but a push in the right direction would be very helpful.Thanks
 
Back
Top