private Image CheckFramePosition(Image imageToCheck) { try { Rectangle rec = DocDetector.FindSquare(new Image <Bgr, Byte>(new Bitmap((Image)imageToCheck))); // находим положение паспорта Bitmap croppedImage = DocDetector.CropImage(new Bitmap(imageToCheck), rec); // вырезаем паспорт if (croppedImage.Height > croppedImage.Width) { imageToCheck.RotateFlip(RotateFlipType.Rotate90FlipNone); } return(imageToCheck); } catch (Exception) { //Console.WriteLine("Coulnt find document"); logger.Error("Coulnt find document"); return(imageToCheck); } }
private FindResult FindFace(Image InputImage) { int counter = 0; float face_width, face_height, face_delta_min, face_delta_max; int dpi; try { face_width = float.Parse(ConfigurationManager.AppSettings["face_width"], System.Globalization.CultureInfo.InvariantCulture); face_height = float.Parse(ConfigurationManager.AppSettings["face_height"], System.Globalization.CultureInfo.InvariantCulture); face_delta_min = float.Parse(ConfigurationManager.AppSettings["face_delta_min"], System.Globalization.CultureInfo.InvariantCulture); face_delta_max = float.Parse(ConfigurationManager.AppSettings["face_delta_max"], System.Globalization.CultureInfo.InvariantCulture); dpi = int.Parse(ConfigurationManager.AppSettings["ScannerDpi"]); } catch { //Console.WriteLine("Не смог считать параметры face_wigth и.т.д."); logger.Error("Не смог считать параметры face_wigth и.т.д."); face_width = 2.0f; face_height = 2.6f; face_delta_min = 0.2f; face_delta_max = 0.9f; dpi = 300; } double minRectangleSquare = face_width * face_height * face_delta_min; double maxRectamgleSquare = face_width * face_height * face_delta_max; int goodFacesFound = 0; var Result = new FindResult(false, null); while (counter <= 3) { FaceDetectorProcessor scanFaceDetectorProcessor = new FaceDetectorProcessor(new Image <Bgr, byte>(new Bitmap(InputImage))); Rectangle[] facesOnScan = scanFaceDetectorProcessor.isFaceDetected(); goodFacesFound = 0; double RectangleSquare = 0; foreach (var item in facesOnScan) { RectangleSquare = ((double)item.Width / Math.Round(InputImage.HorizontalResolution) * 2.54 * ((double)item.Height / Math.Round(InputImage.HorizontalResolution)) * 2.54); var croppedFace = DocDetector.CropImage(new Bitmap(InputImage), item); if (checkFaceSquare(RectangleSquare, minRectangleSquare, maxRectamgleSquare)) { croppedFace.Save("ScanCropedFaceGood" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".jpg"); Result.update(true, croppedFace); goodFacesFound++; } else { Result.update(false, croppedFace); croppedFace.Save("ScanCropedFaceBad" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".jpg"); } } if (goodFacesFound == 1) { return(Result); //return new FindResult(true,) } InputImage.RotateFlip(RotateFlipType.Rotate90FlipNone); scanFaceDetectorProcessor = null; facesOnScan = null; counter++; System.Windows.Forms.Application.DoEvents(); } return(Result); }