public void FaceUpdat2eTest() { var image = Bitmap.FromFile(@"Elise.jpg"); var groupId = "EE"; var userId = "Elise"; var option = new FaceOption() { User_Info = "高小娜 新娘 请就坐1号桌." }; var jObj = FaceApi.FaceUpdate(new Bitmap(image), groupId, userId, option); image.Dispose(); }
public void FaceRegisterTest() { var image = Bitmap.FromFile(@"Ego.jpg"); var groupId = "EE"; var userId = "HuangGuangyi3"; var option = new FaceOption() { User_Info = "hhhhhhhhhhhhhhh" }; var jObj = FaceApi.FaceRegister(new Bitmap(image), groupId, userId, option); image.Dispose(); }
public static bool SaveOrUpdateFace(GuestInfo info) { bool success = false; try { if (string.IsNullOrEmpty(info.Id)) { info.Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } var guest = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == info.Id); string imageFileName = null; if (!string.IsNullOrEmpty(info.ImagePath) && (info.ImagePath != guest?.ImagePath || guest == null)) { imageFileName = Path.Combine($"GuestImages\\{info.Id}.jpg"); var img = Bitmap.FromFile(info.ImagePath); var option = new FaceOption() { User_Info = $"姓名: {info.Name} \n身份: {info.Labels}\n桌号: {info.TableNo} ", }; var jObj = FaceApi.FaceSaveOrUpdate(new Bitmap(img), GlobalConfigs.Configurations.GroupId, guest != null ? guest.Id : info.Id, option); success = (jObj != null && jObj.error_code == 0); if (success) { var newImage = new Bitmap(img); img.Dispose(); if (File.Exists(imageFileName)) { File.Delete(imageFileName); } newImage.Save(imageFileName, ImageFormat.Jpeg); newImage.Dispose(); } } else { success = true; } if (success) { var entourageText = info.Entourage ?? ""; var entourages = entourageText.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var entourageNum = entourages.Count(); if (guest == null)//新增 { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = info.Id, Name = info.Name, FullName = info.Name, Gender = info.Gender, GuestType = info.GuestType, Entourage = entourageText, EntourageNum = entourageNum, Labels = info.Labels, TableNo = info.TableNo, ImagePath = imageFileName, CashGift = info.CashGift, CreateTime = DateTime.Now, }); if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = info.Id, Name = $"{item}", FullName = $"{info.Name}_{item}", Gender = 0, GuestType = info.GuestType, Entourage = "", EntourageNum = 0, Labels = $"{info.Name} 随行人员", TableNo = info.TableNo, ImagePath = null, CreateTime = DateTime.Now, }); } } } else { var oldName = guest.Name; guest.Name = info.Name; guest.Gender = info.Gender; guest.GuestType = info.GuestType; guest.Labels = info.Labels; guest.TableNo = info.TableNo; guest.ImagePath = imageFileName; guest.CashGift = info.CashGift; guest.CreateTime = DateTime.Now; if (guest.Entourage != info.Entourage) { GlobalConfigs.Guests.RemoveAll(x => x.ParentId == info.Id); guest.Entourage = entourageText; guest.EntourageNum = entourageNum; if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = info.Id, Name = $"{item}", FullName = $"{info.Name}_{item}", Gender = 0, GuestType = info.GuestType, Entourage = "", EntourageNum = 0, Labels = $"{info.Name} 随行人员", TableNo = info.TableNo, ImagePath = null, IsAttend = guest.IsAttend, AttendTime = guest.AttendTime, CreateTime = DateTime.Now, }); } } } #region 关联更新 var parent = GlobalConfigs.Guests.FirstOrDefault(x => x.Id == guest.ParentId); if (parent != null && !string.IsNullOrEmpty(parent.Entourage)) { var pEntourages = parent.Entourage.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < pEntourages.Length; i++) { if (pEntourages[i] == oldName) { pEntourages[i] = guest.Name; } } parent.Entourage = string.Join(",", pEntourages); parent.EntourageNum = pEntourages.Count(); guest.FullName = $"{parent.Name}_{guest.Name}"; } #endregion } GlobalConfigMgr.SaveGuests(); } return(success); } catch (Exception ex) { return(false); } }
private bool?SaveOrUpdate(GuestInfo info) { bool success = false; try { var name = info.Name; var gender = info.Gender; var labels = info.Labels; var tableNo = info.TableNo; var imagePath = info.ImagePath; var entourageText = info.Entourage; var guestType = info.GuestType; var userId = info.Id; if (string.IsNullOrEmpty(userId)) { userId = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } var imageFileName = Path.Combine($"GuestImages\\{userId}.jpg"); var img = Bitmap.FromFile(imagePath); var option = new FaceOption() { User_Info = $"姓名: {name} \n身份: {labels}\n桌号: {tableNo} ", }; var guest = GlobalConfigs.Guests.FirstOrDefault(x => x.Name == name); BaseResponse <FaceRegisterResult> jObj; if (guest == null)//新增 { jObj = FaceApi.FaceSaveOrUpdate(new Bitmap(img), GlobalConfigs.Configurations.GroupId, userId, option); success = (jObj != null && jObj.error_code == 0); if (success) { var entourages = entourageText.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var entourageNum = entourages.Count(); GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = userId, Name = name, Gender = gender, GuestType = guestType, Entourage = entourageText, EntourageNum = entourageNum, Labels = labels, TableNo = tableNo, ImagePath = imageFileName, CreateTime = DateTime.Now, }); if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(), ParentId = userId, Name = $"{name}_{item}", Gender = 0, GuestType = guestType, Entourage = "", EntourageNum = 0, Labels = labels, TableNo = tableNo, ImagePath = null, CreateTime = DateTime.Now, }); } } GlobalConfigMgr.SaveGuests(); } } else { jObj = FaceApi.FaceSaveOrUpdate(new Bitmap(img), GlobalConfigs.Configurations.GroupId, guest.Id, option); success = (jObj != null && jObj.error_code == 0); if (success) { var entourages = entourageText.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); var entourageNum = entourages.Count(); guest.Name = name; guest.Gender = gender; guest.GuestType = guestType; guest.Entourage = entourageText; guest.EntourageNum = entourageNum; guest.Labels = labels; guest.TableNo = tableNo; guest.ImagePath = null; guest.CreateTime = DateTime.Now; for (int i = 0; i < GlobalConfigs.Guests.Count; i++) { if (GlobalConfigs.Guests[i].ParentId == userId) { GlobalConfigs.Guests.Remove(GlobalConfigs.Guests[i]); } } if (entourages != null) { foreach (var item in entourages) { GlobalConfigs.Guests.Add(new ee.Models.GuestInfo() { Id = System.Guid.NewGuid().ToString().ToUpper(), ParentId = userId, Name = $"{name}_{item}", Gender = 0, GuestType = guestType, Entourage = "", EntourageNum = 0, Labels = labels, TableNo = tableNo, ImagePath = null, IsAttend = guest.IsAttend, AttendTime = guest.AttendTime, CreateTime = DateTime.Now, }); } } GlobalConfigMgr.SaveGuests(); } } var newImage = new Bitmap(img); img.Dispose(); if (File.Exists(imageFileName)) { File.Delete(imageFileName); } newImage.Save(imageFileName, ImageFormat.Jpeg); newImage.Dispose(); return(success); } catch (Exception ex) { return(false); } }
public static BaseResponse <FaceRegisterResult> FaceUpdate(Bitmap image, string groupId, string userId, FaceOption option = null) { return(FaceUpdate(image.ToBytes(), groupId, userId, option)); }
public static BaseResponse <FaceRegisterResult> FaceUpdate(byte[] imageByte, string groupId, string userId, FaceOption option = null) { if (imageByte.Length > 1024 * 1024 * 10) { throw new Exception("图片大小必须小于10Mb"); } var imageBase64 = Convert.ToBase64String(imageByte); return(Execute <FaceRegisterResult>(client.UserUpdate(imageBase64, ImageType, groupId, userId, option?.Options))); }
public static BaseResponse <FaceRegisterResult> FaceSaveOrUpdate(Bitmap image, string groupId, string userId, FaceOption option = null) { var user = GetUserInfo(userId, groupId); if (user != null && user.error_code == 0 && (user.result?.user_list?.Any() ?? false)) { return(FaceUpdate(image, groupId, userId, option)); } else { return(FaceRegister(image, groupId, userId, option)); } }
public static BaseResponse <FaceRegisterResult> FaceRegister(Bitmap image, string groupId, string userId, FaceOption option = null) { var imageByte = image.ToBytes(); return(FaceRegister(imageByte, groupId, userId, option)); }