public static List <FaceAdded> SaveTrainingData(string ImagePath, int[] FaceIDs, int[] StudentIDs)
        {
            Image <Bgr, byte> Image      = new Image <Bgr, byte>(ImagePath);
            List <FaceAdded>  FacesAdded = new List <FaceAdded>();

            StudentImageBusiness StuImaBO = new StudentImageBusiness();

            using (Image <Gray, byte> GrayImage = Image.Clone().Convert <Gray, byte>())
            {
                var FacesDetected = GrayImage.DetectHaarCascade(Haar, DETECT_SCALE, MIN_NEIGHBOR,
                                                                0, new System.Drawing.Size(MIN_SIZE, MIN_SIZE))[0];
                foreach (int FaceID in FaceIDs)
                {
                    int StudentID = StudentIDs[FaceID];
                    //Neu ko phai unknow thi moi save, la unknown thi bo qua
                    if (StudentID != 0)
                    {
                        var Face = FacesDetected[FaceID];
                        Image <Bgr, byte> FaceImage = Image.Copy(Face.rect)
                                                      .Resize(TRAINING_DATA_SIZE, TRAINING_DATA_SIZE,
                                                              INTER.CV_INTER_CUBIC);

                        //Tao ten file
                        String ImageName = System.IO.Path.GetFileNameWithoutExtension(ImagePath);
                        String FileName  = String.Format("{0}_face_{1}.jpg", ImageName, FaceID);

                        //Save anh, ghi xuong database
                        if (StuImaBO.ImageExist(StudentID, FileName))
                        {
                            throw new Exception(FileName);
                        }
                        else
                        {
                            //Save file anh xuong
                            FaceImage.Save(TRAINING_FOLDER_PATH + "/" + FileName);
                            //Save xuong DB
                            StudentImage StuIma = new StudentImage()
                            {
                                StudentID = StudentID, ImageLink = FileName
                            };
                            StuImaBO.Insert(StuIma);
                            //Dua KQ tra ra
                            FacesAdded.Add(new FaceAdded()
                            {
                                FaceLink = FileName, StudentID = StudentID, ImageID = StuIma.ImageID
                            });
                        }
                    }
                }
            }

            Image.Dispose();

            return(FacesAdded);
        }
Beispiel #2
0
        public AdminController()
        {
            RSMEntities db = new RSMEntities();

            StuBO     = new StudentBusiness(db);
            ClaBO     = new ClassBusiness(db);
            ReBO      = new RequestBusiness(db);
            SlFactory = new SelectListFactory(db);
            StaffBO   = new StaffBusiness(db);
            AccBO     = new AccountBusiness(db);
            StuImBO   = new StudentImageBusiness(db);
        }
        public static void SaveTrainingData(string ImagePath, int FaceID, int StudentID)
        {
            //Ben ngoai ko check, ko save
            if (FaceID == -1)
            {
                return;
            }

            StudentImageBusiness StuImaBO = new StudentImageBusiness();

            Image <Bgr, byte> Image = new Image <Bgr, byte>(ImagePath);

            using (Image <Gray, byte> GrayImage = Image.Clone().Convert <Gray, byte>())
            {
                var FacesDetected = GrayImage.DetectHaarCascade(Haar, DETECT_SCALE, MIN_NEIGHBOR,
                                                                0, new System.Drawing.Size(MIN_SIZE, MIN_SIZE))[0];
                Image <Bgr, byte> FaceImage = Image.Copy(FacesDetected[FaceID].rect)
                                              .Resize(TRAINING_DATA_SIZE, TRAINING_DATA_SIZE,
                                                      INTER.CV_INTER_CUBIC);;

                //Tao ten file
                String ImageName = System.IO.Path.GetFileNameWithoutExtension(ImagePath);
                String FileName  = String.Format("{0}_face_{1}.jpg", ImageName, FaceID);

                if (StuImaBO.ImageExist(StudentID, FileName))
                {
                    throw new Exception(FileName);
                }
                else
                {
                    //Save file anh xuong
                    FaceImage.Save(TRAINING_FOLDER_PATH + "/" + FileName);
                    //Save xuong DB
                    StudentImage StuIma = new StudentImage()
                    {
                        StudentID = StudentID, ImageLink = FileName
                    };
                    StuImaBO.Insert(StuIma);
                }
            }
            Image.Dispose();
        }
 public ImageController()
 {
     ReBO     = new RequestBusiness();
     StuImaBO = new StudentImageBusiness();
 }