public ActionResult CreateRequestImage(FormCollection Form) { int StudentID = int.Parse(Form["StudentID"]); int requestID = int.Parse(Form["requestID"]); List <String> ErrorList = new List <String>(); //Moi anh se co 1 id, luu face region co id nay vao database String[] FilesPath = Form["ImageLink"].Split(','); String[] FaceIDs = Form["FaceID"].Split(','); var req = ReBO.GetRequestByID(requestID); req.IsResponse = true; ReBO.UpdateExist(req); for (int i = 0; i < FilesPath.Length; i++) { String ImagePath = Server.MapPath("~/Content/Temp/Resized/" + FilesPath[i]); int FaceID = int.Parse(FaceIDs[i]); try { FaceBusiness.SaveRequestImage(ImagePath, FaceID, StudentID, requestID); } catch (Exception e) { ErrorList.Add(e.Message); } } TempData["Errors"] = ErrorList; //Cat image ra, cat face index ra, gui lai trang single return(RedirectToAction("CourseList", "Student")); }
public ActionResult SaveImageSingle(FormCollection Form) { int StudentID = int.Parse(Form["StudentID"]); List <String> ErrorList = new List <String>(); //Moi anh se co 1 id, luu face region co id nay vao database String[] FilesPath = Form["ImageLink"].Split(','); String[] FaceIDs = Form["FaceID"].Split(','); for (int i = 0; i < FilesPath.Length; i++) { String ImagePath = Server.MapPath("~/Content/Temp/Resized/" + FilesPath[i]); int FaceID = int.Parse(FaceIDs[i]); try { FaceBusiness.SaveTrainingData(ImagePath, FaceID, StudentID); } catch (Exception e) { ErrorList.Add(e.Message); } } TempData["Errors"] = ErrorList; //Cat image ra, cat face index ra, gui lai trang single return(RedirectToAction("SingleStudent", "Admin", new { StudentID = StudentID })); }
//student view image or upload image public ActionResult ResonpeRequest(int StudentID, int requestID, IEnumerable <HttpPostedFileBase> ImageFiles) { ViewBag.RequestID = requestID; ViewBag.StudentID = StudentID; var student = StuBO.GetStudentByID(StudentID); ViewBag.StudentCode = student.StudentCode; ViewBag.StudentName = student.FullName; List <RecognizerResult> Results = new List <RecognizerResult>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh String NewPath = Server.MapPath("~/Content/Temp/Resized/" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); //Nhan dien khuon mat, cho vao danh sach RecognizerResult SingleResult = FaceBusiness.DetectFromImage(NewPath); Results.Add(SingleResult); } return(View("StudentImageResult", Results)); }
public ActionResult SelectLogImage(IEnumerable <int> ImageIDs) { LogBusiness LogBO = new LogBusiness(); //Lay nhung image da chon tu db, sort theo rollcall ID List <LogImage> ImageList = ImageIDs.Select(id => LogBO.GetLogImageByID(id)) .OrderBy(img => img.AttendanceLog.RollCallID).ToList(); List <int> RollCallIDs = ImageList.Select(img => img.AttendanceLog.RollCallID).Distinct().ToList(); List <RecognizerResult> Result = new List <RecognizerResult>(); foreach (int RollCallID in RollCallIDs) { List <LogImage> RollCallImages = ImageList.Where(img => img.AttendanceLog.RollCallID == RollCallID).ToList(); List <String> ImagePaths = RollCallImages.Select(img => Server.MapPath("~/Content/Log/" + img.ImageLink)).ToList(); //Nhan dien khuon mat, dua vao list de show ra Result.AddRange(FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths)); } //Danh sash student de tao select list ViewBag.Students = StuBO.GetAllStudents(); return(View("LogImagesResult", Result)); }
public ActionResult AddImages(IEnumerable <HttpPostedFileBase> ImageFiles) { List <RecognizerResult> Results = new List <RecognizerResult>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh String NewPath = Server.MapPath("~/Content/Temp/Resized/" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); //Nhan dien khuon mat, cho vao danh sach RecognizerResult SingleResult = FaceBusiness.DetectFromImage(NewPath); Results.Add(SingleResult); } //Load may cai selectbox vao day var Students = StuBO.GetActiveStudents(); ViewBag.Students = Students; return(View("AddImagesResult", Results)); }
public ActionResult Config(ConfigModel Model) { if (ModelState.IsValid) { ViewBag.Message = "Setting saved."; ConfigHelper.SaveConfig(Model); FaceBusiness.Initialize(); } return(View(Model)); }
public ActionResult CheckAttendanceAuto(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles) { RollCall rollCall = RollBO.GetRollCallByID(RollCallID); List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop String NewPath = Server.MapPath("~/Content/Log/" + rollCall.Class.ClassName + "_" + rollCall.Subject.ShortName + "_" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); } //Nhan dien tung khuon mat trong anh List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); //Dua reseult nay cho AttendanceBO xu ly AttendanceBusiness AttenBO = new AttendanceBusiness(); AttendanceLog Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Result); //Danh sach sinh vien trong log StudentBusiness StuBO = new StudentBusiness(); List <Student> Students = StuBO.Find(stu => stu.StudentAttendances. Any(attend => attend.LogID == Log.LogID && attend.IsPresent)).ToList(); RollCall CurrentRollCall = RollBO.GetRollCallByID(RollCallID); //Tao model de show trong view AttendanceViewModel model = new AttendanceViewModel(); model.CurrentRollCall = CurrentRollCall; model.PresentStudents = Students; model.RecognizeResult = Result; return(View(model)); }
public ActionResult RecognizeTesting(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles) { List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop String NewPath = Server.MapPath("~/Content/Temp/Resized/" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); } //Nhan dien tung khuon mat trong anh List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); return(View("RecognizeTestingResult", Result)); }
public ActionResult SaveImageMulti(ImageBindingModel model) { List <String> ErrorList = new List <String>(); List <FaceAdded> FacesAdded = new List <FaceAdded>(); foreach (var SingeImageModel in model.ImageModels) { //Lay file name, lay cac gia tri face va value String ImageLink = SingeImageModel.ImageLink; int[] FaceIndexs = SingeImageModel.FaceIndexs.ToArray(); int[] UserIDs = SingeImageModel.StudentIDs.ToArray(); String ImagePath = ""; if (model.Folder.Equals("Resized")) { ImagePath = Server.MapPath("~/Content/Temp/Resized/" + ImageLink); } else if (model.Folder.Equals("Log")) { ImagePath = Server.MapPath("~/Content/Log/" + ImageLink); } if (FaceIndexs != null && UserIDs != null) { try { //Lay danh sach, dua ra FacesAdded.AddRange(FaceBusiness.SaveTrainingData(ImagePath, FaceIndexs, UserIDs)); } catch (Exception e) { ErrorList.Add(e.Message); } } } FacesAdded.OrderBy(fa => fa.StudentID); TempData["FacesAdded"] = FacesAdded; TempData["Errors"] = ErrorList; return(Redirect(model.ReturnUrl)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); ConfigHelper.SetConfigFile(Server.MapPath("~/Config.xml")); SimpleLog.SetLogFolder(Server.MapPath("~/Content/Log/TextLog")); FaceBusiness.Initialize(); FaceBusiness.SetXMLPath(Server.MapPath("~/")); FaceBusiness.SetTrainingFolderPath(Server.MapPath("~/Content/Training Data")); //Bat dau set cai scheduler PathHolder.TempPath = Server.MapPath("~/Content/Temp/"); PathHolder.LogoPath = Server.MapPath("~/Content/") + "png-logo_resize.png"; // PathHolder.LogoPath = Server.MapPath("~/Content/") + "fu_logo_edited.png"; TaskManager.Initialize(new MyRegistry()); TaskManager.UnobservedTaskException += TaskManager_UnobservedTaskException; }
public ActionResult CheckAttendanceAuto(int RollCallID, List <HttpPostedFileBase> ImageFiles, DateTime?AttendanceDate) { RollCallBusiness RollBO = new RollCallBusiness(); var rollCall = RollBO.GetRollCallByID(RollCallID); List <String> ImagePaths = new List <string>(); foreach (HttpPostedFileBase file in ImageFiles) { //Save file anh xuong String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName); file.SaveAs(OldPath); //Resize file anh, luu vao thu muc log, nho them ngay thang truoc String NewPath = Server.MapPath("~/Content/Log/" + rollCall.Class.ClassName + "_" + rollCall.Subject.ShortName + "_" + file.FileName); FaceBusiness.ResizeImage(OldPath, NewPath); ImagePaths.Add(NewPath); //Nhan dien tung khuon mat trong anh } List <RecognizerResult> Results = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths); //Dua result nay cho AttendanceBO xu ly AttendanceBusiness AttenBO = new AttendanceBusiness(); AttendanceLog Log = null; if (AttendanceDate == null) { Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results); } else { Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results, AttendanceDate.Value); } //Danh sach sinh vien trong log List <int> StudentIDs = AttenBO.GetStudentIDList(Results); //Lay danh sach sinh vien ton tai trong log StudentBusiness StuBO = new StudentBusiness(); //List<Student> Students = StuBO.Find(stu => StudentIDs.Contains(stu.StudentID)).ToList(); /* * var StudentsJson = Students.ToList().Select(s => new * { * studentID = s.StudentID, * studentCode = s.StudentCode, * studentName = s.FullName * }); */ var StudentsJson = Log.StudentAttendances.Select(sa => new { studentID = sa.StudentID, studentCode = sa.Student.StudentCode, studentName = sa.Student.FullName, isPresent = sa.IsPresent }); return(Json(StudentsJson, JsonRequestBehavior.AllowGet)); }