static void CompareHaarTimesBigImageResized() { FaceBO_HaarChangable.SetXMLPath("HaarXML"); Console.WriteLine("For Face Detection. We have 4 haarXML file.\nWe will check the time to detect face with each file."); Console.WriteLine("We will test with a folder contain 100 images. Image Resolution is 2200px x 1500px."); Console.WriteLine("The image will be resized to 1100px x 750px before detecting."); String FolderPath = @"C:\Users\Hoang\Documents\Visual Studio 2010\Projects\RollSystemMobile\FaceRecAutomationTesting\Sample Images\Sample Images 2"; Console.Write("Press Enter to begin: "); Console.ReadLine(); List <HaarType> HaarTypes = new List <HaarType>(); HaarTypes.Add(HaarType.AltTree); HaarTypes.Add(HaarType.Alt1); HaarTypes.Add(HaarType.Alt2); HaarTypes.Add(HaarType.Default); foreach (var Type in HaarTypes) { FaceBO_HaarChangable.Haar = FaceBO_HaarChangable.CreateHaar(Type); Console.WriteLine("Begin testing for Haar " + Type + ":\n"); DateTime Start = DateTime.Now; int index = 1; foreach (var FilePath in Directory.GetFiles(FolderPath, "*.jpg")) { FaceBO_HaarChangable.DetectFromImageWithResize(FilePath); Console.WriteLine("\tDetect " + index + " images."); index++; } TimeSpan TimeDiff = DateTime.Now - Start; Console.WriteLine("Time to run 100 detects is: " + TimeDiff.TotalMilliseconds / 1000 + " seconds"); Console.Write("Press enter to continue: "); Console.ReadLine(); } }
//So sanh do chinh xac, hit ma miss cua cac bo haar static void CompareAccuracySingleImage() { FaceBO_HaarChangable.SetXMLPath("HaarXML"); Console.WriteLine("This time, we will check the accuraccy of detection."); Console.WriteLine("We will test with a folder contain 100 images."); String FolderPath = @"C:\Users\Hoang\Documents\Visual Studio 2010\Projects\RollSystemMobile\FaceRecAutomationTesting\Sample Images"; Console.Write("Press Enter to begin: "); Console.ReadLine(); List <HaarType> HaarTypes = new List <HaarType>(); HaarTypes.Add(HaarType.AltTree); HaarTypes.Add(HaarType.Alt1); HaarTypes.Add(HaarType.Alt2); HaarTypes.Add(HaarType.Default); int NumberOfFile = Directory.GetFiles(FolderPath, "*.jpg").Count(); foreach (var Type in HaarTypes) { FaceBO_HaarChangable.Haar = FaceBO_HaarChangable.CreateHaar(Type); Console.WriteLine("Begin testing for Haar " + Type + ":\n"); int index = 1; double Hit = 0; double MissingHit = 0; double OverHit = 0; int DetectFaceCount = 0; int TotalFace = 0; foreach (var FilePath in Directory.GetFiles(FolderPath, "*.jpg")) { RecognizerResult result = FaceBO_HaarChangable.DetectFromImage(FilePath); int FaceDetected = result.FaceList.Count; int FaceInImage = GetResult(FilePath); String Report = String.Format("\tDetect {0} image. Find {1}/{2} faces.", index, FaceDetected, FaceInImage); if (FaceDetected == FaceInImage) { Report += "(O)"; Hit++; } else { if (FaceDetected < FaceInImage) { MissingHit++; } else { OverHit++; } Report += "(X)"; } Console.WriteLine(Report); index++; DetectFaceCount += FaceDetected; TotalFace += FaceInImage; } Console.WriteLine(String.Format("Accuracy: {0}%. Missing: {1}%. Over Detect: {2}%.", (Hit / NumberOfFile), (MissingHit / NumberOfFile), (OverHit / NumberOfFile))); Console.WriteLine(String.Format("Detected {0}/{1} faces", DetectFaceCount, TotalFace)); Console.Write("Press enter to continue: "); Console.ReadLine(); } }