コード例 #1
0
        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);
        }
コード例 #2
0
        public IActionResult Index()
        {
            StudentImage studentImages = new StudentImage()
            {
                Students = Images.GetStudents(),
                MyImages = Images.GetImages(),
                Numbers  = Images.GetNumbers()
            };

            ViewBag.Name = "It's interesting";
            // return View(Images.GetImages());
            return(View(studentImages));
        }
コード例 #3
0
        public ActionResult AcceptRequest(int requestID, String name)
        {
            var adminID = AccBO.GetUserByUsername(name).UserID;
            var req     = ReBO.GetRequestByID(requestID);

            req.CheckedAdminID = adminID;
            ReBO.UpdateExist(req);

            foreach (var rq in req.RequestImages)
            {
                var stImage = new StudentImage();
                stImage.StudentID = rq.Request.StudentID;
                stImage.ImageID   = rq.ImageID;
                stImage.ImageLink = rq.ImageLink;
                StuImBO.Insert(stImage);
            }

            return(RedirectToAction("StudentRequest"));
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        } //--------------------------------------

        #endregion

        #region Programmer-Defined Function Procedures

        //this function gets the student image details
        private StudentImage GetStudentImageDetails(String studentId)
        {
            StudentImage imageInfo = new StudentImage();

            DirectoryInfo dirInfo = new DirectoryInfo(_imagePath);

            FileInfo[] fileInfo = dirInfo.GetFiles(studentId + "*", SearchOption.AllDirectories);

            foreach (FileInfo fi in fileInfo)
            {
                if (String.Equals(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length), studentId))
                {
                    imageInfo.ImagePath      = fi.FullName;
                    imageInfo.ImageExtension = fi.Extension;
                    break;
                }
            }

            return(imageInfo);
        } //-------------------------------------
コード例 #6
0
        } //------------------------

        //this procedure exports the student data to the sql server
        private void ExportStudentDataToSqlServer()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Int32 deniedCount  = 0;
                Int32 successCount = 0;
                Int32 rowCount     = 0;

                pgbImport.Step    = 1;
                pgbImport.Maximum = this.dgvList.Rows.Count;

                foreach (DataRow studRow in _studentTable.Rows)
                {
                    this.SetDataGridViewBehavior(rowCount);

                    String studentId   = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "ACCESSION", "");
                    String cardNumber  = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "KEYWORDS", "");
                    String studentName = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "TITLE0", "");

                    if (!this.IsExistStudentIdStudentInformation(_userInfo, studentId, "") &&
                        !this.IsExistCardNumberStudentInformation(_userInfo, cardNumber, "") &&
                        !String.Equals("(blank)", studentName) &&
                        !String.IsNullOrEmpty(RemoteClient.ProcStatic.TrimStartEndString(cardNumber)) &&
                        !String.IsNullOrEmpty(RemoteClient.ProcStatic.TrimStartEndString(studentId)))
                    {
                        String remarks = RemoteServerLib.ProcStatic.DataRowConvert(studRow, "REMARKS", "");

                        CommonExchange.Student studentInfo = new CommonExchange.Student();

                        studentInfo.ObjectState            = DataRowState.Added;
                        studentInfo.PersonInfo.ObjectState = DataRowState.Added;

                        StudentName    studName   = this.GetStudentNameDetails(studentName);
                        RemarksDetails remarkInfo = this.GetRemarksDetails(remarks);

                        studentInfo.StudentId            = RemoteClient.ProcStatic.TrimStartEndString(studentId);
                        studentInfo.PersonInfo.LastName  = studName.LastName;
                        studentInfo.PersonInfo.FirstName = studName.FirstName;
                        studentInfo.CardNumber           = cardNumber;
                        studentInfo.Scholarship          = studName.Scholoarship;
                        studentInfo.CourseInfo.CourseId  = this.GetCourseId(remarkInfo.CourseName);
                        studentInfo.PersonInfo.OtherPersonInformation = remarkInfo.OtherInformation;
                        studentInfo.PersonInfo.BirthDate = String.Empty;

                        if (!String.IsNullOrEmpty(_imagePath) && this.chkImage.Checked)
                        {
                            StudentImage imageInfo = this.GetStudentImageDetails(studentId);

                            if (!String.IsNullOrEmpty(imageInfo.ImagePath))
                            {
                                studentInfo.PersonInfo.FilePath      = imageInfo.ImagePath;
                                studentInfo.PersonInfo.FileData      = RemoteClient.ProcStatic.GetFileArrayBytes(imageInfo.ImagePath);
                                studentInfo.PersonInfo.FileExtension = imageInfo.ImageExtension;
                                studentInfo.PersonInfo.FileName      = Path.GetFileName(imageInfo.ImagePath);

                                this.txtDirectory.Text = imageInfo.ImagePath;
                            }
                        }

                        using (RemoteClient.RemCntStudentManager remClient = new RemoteClient.RemCntStudentManager())
                        {
                            remClient.InsertStudentInformation(_userInfo, ref studentInfo);
                        }

                        using (RemoteClient.RemCntIdMakerManager remClient = new RemoteClient.RemCntIdMakerManager())
                        {
                            remClient.UpdateForIdMakerStudentInformation(_userInfo, studentInfo);
                        }

                        successCount++;
                    }
                    else
                    {
                        deniedCount++;
                    }

                    pgbImport.PerformStep();

                    rowCount++;

                    Application.DoEvents();
                    this.Refresh();
                }

                MessageBox.Show("Student data has been successfully exported to the SQL Server" + "\n\nSuccess: " + successCount.ToString() + " Record(s)" +
                                "\nDenied: " + deniedCount.ToString() + " Record(s)", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                pgbImport.Value = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in exporting: " + ex.Message, "Error");
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        } //--------------------------------------