public ActionResult EditPerson(PersonInfo personinfo) { _faceService = new FaceDP(Server.MapPath("~")); DataTable dt = _faceService.GetGenderCode(); ViewBag.GenderCode = _webModel.MapCodeData(dt); _faceService.UpdatePersonInfo(personinfo); return(View("ManagementPage")); }
public ActionResult AddNewPerson() { _faceService = new FaceDP(Server.MapPath("~")); _personInfoModel = new PersonInfo(); DataTable dt = _faceService.GetGenderCode(); ViewBag.GenderCode = _webModel.MapCodeData(dt); return(View(_personInfoModel)); }
public ActionResult AddNewPerson(PersonInfo tempPerson) { _faceService = new FaceDP(Server.MapPath("~")); _personInfoModel = new PersonInfo(); DataTable dt = _faceService.GetGenderCode(); ViewBag.GenderCode = _webModel.MapCodeData(dt); if (ModelState.IsValid) { TempData["notice"] = _faceService.CreatePerson(tempPerson); return(View("ManagementPage")); } return(View(_personInfoModel)); }
public ActionResult EditPerson(int userId) { _faceService = new FaceDP(Server.MapPath("~")); DataTable dt = _faceService.GetGenderCode(); ViewBag.GenderCode = _webModel.MapCodeData(dt); DataTable personInfo = _faceService.GetPersonInfo(userId); var tempPerson = new PersonInfo { userId = Convert.ToInt64(personInfo.Rows[0]["userId"]), userName = personInfo.Rows[0]["userName"].ToString(), gender = personInfo.Rows[0]["gender"].ToString(), birthDate = Convert.ToDateTime(personInfo.Rows[0]["birthDate"].ToString()), tag = personInfo.Rows[0]["tag"].ToString() }; return(View(tempPerson)); }
public ActionResult Submit(HttpPostedFileBase file) { _faceService = new FaceDP(Server.MapPath("~")); ViewBag.NullFile = false; ViewBag.WrongFileType = false; if (file == null) { ViewBag.NullFile = true; return(View()); } if (file.ContentType != "image/jpeg") { ViewBag.WrongFileType = true; return(View()); } //翻轉處理 //Bitmap originImg = ConvertFileToImage(files).ToBitmap(); var originImg = FileToImageRotate(file); //傳入影像做臉部偵測 //Image<Bgr, byte> newImage = _faceService.FaceDetection(ConvertFileToImage(files)); Bitmap bitmap = _faceService.FaceDetection(originImg).Resize(450, 800, Emgu.CV.CvEnum.Inter.Linear).ToBitmap(); Bitmap cropFace = _faceService.GetFaceImage().ToBitmap(); //偵測完的人臉做辨識 int userId = _faceService.RecognizeFace(); DataTable user = _faceService.GetPersonInfo(userId); //轉換成bitmap格式,加上辨識後結果於左上角 //Bitmap bitmap = newImage.ToBitmap(); //Bitmap cropFace = _faceService.GetFaceImage().ToBitmap(); //繪製辨識資訊 //Graphics draw = Graphics.FromImage(bitmap); //draw.SmoothingMode = SmoothingMode.AntiAlias; //draw.InterpolationMode = InterpolationMode.HighQualityBicubic; //draw.PixelOffsetMode = PixelOffsetMode.HighQuality; //draw.FillRectangle(Brushes.Black, new Rectangle(0, 0, 150, 35)); //draw.DrawString(userNameLabel, new Font("微軟正黑體", 18, FontStyle.Bold), Brushes.Red, new RectangleF(0, 0, 150, 35)); //draw.Flush(); //轉換影像成Stream var stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Jpeg); var faceStream = new MemoryStream(); cropFace.Save(faceStream, ImageFormat.Jpeg); //to base64 // Convert byte[] to Base64 String var imageBytes = stream.ToArray(); string base64String = Convert.ToBase64String(imageBytes); ViewBag.Image = base64String; imageBytes = faceStream.ToArray(); base64String = Convert.ToBase64String(imageBytes); ViewBag.FaceImage = base64String; //info ViewBag.UserName = user.Rows[0]["userName"].ToString(); ViewBag.UserGender = user.Rows[0]["gender"].ToString(); ViewBag.UserBirthDate = Convert.ToDateTime(user.Rows[0]["birthDate"]).ToString("yyyy/MM/dd"); ViewBag.UserTag = user.Rows[0]["tag"].ToString(); DataTable dt = _faceService.GetGenderCode(); ViewBag.GenderCode = _webModel.MapCodeData(dt); return(View()); }