/// <summary> /// 设置初始值 /// </summary> /// <param name="myFaceObj"></param> /// <param name="i">1:添加模版 2:修改模版 3:抓拍修改模版</param> /// <param name="image">从抓拍处添加模版,传入的图片</param> public void SetTempleteInfo(MyFaceObj myFaceObj, int i, byte[] image) { if (i == 2) { tIPViewModel.Id = myFaceObj.fa_ob_tcUuid + ""; tIPViewModel.ImportTime = myFaceObj.fa_ob_dTm; tIPViewModel.Remark = myFaceObj.fa_ob_tcRemarks; tIPViewModel.Age = myFaceObj.nAge + ""; tIPViewModel.Name = myFaceObj.tcName; tIPViewModel.SelectedSex = tIPViewModel.Sex.IndexOf(myFaceObj.nSex); tIPViewModel.SelectedType = tIPViewModel.Type.IndexOf(myFaceObj.nType); tIPViewModel._FaceObj = myFaceObj.faceObj; tIPViewModel.Title = @"..\..\Images\子菜单修改模板.png"; } else { string StringName = System.Guid.NewGuid().ToString(); StringName = StringName.Replace("-", ""); tIPViewModel.Id = StringName; tIPViewModel.ImportTime = DateTime.Now.ToString(); if (i == 3) { tIPViewModel._FaceObj.Tmplate = new List <FaceObjTemplate>(); FaceObjTemplate faceObjectTemplate = new FaceObjTemplate(); faceObjectTemplate.Img = image; tIPViewModel._FaceObj.Tmplate.Add(faceObjectTemplate); } tIPViewModel.Title = @"..\..\Images\子菜单添加模板.png"; } }
/// <summary> /// 确定按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDetermineAddTemplate_Click(object sender, RoutedEventArgs e) { List <ErrorInfo> ListErrorInfo; try { #region 添加输入项 if (btnUuid.Content.ToString() != string.Empty) { tIPViewModel._FaceObj.TcUuid = btnUuid.Content.ToString(); } else { //MyMessage.showYes("人员ID是必输项!"); MyMessage.showYes("人员ID是必输项!"); return; } if (txtName.Text.Trim() != string.Empty) { tIPViewModel._FaceObj.TcName = txtName.Text.Trim(); } else { //MyMessage.showYes("人员名称是必输项!"); MyMessage.showYes("人员名称是必输项!"); return; } if (txtAge.Text.Trim() != string.Empty) { string message = _validationRule.intValidationRule(this.txtAge.Text.Trim()); if (message != "") { //MyMessage.showYes(message); MyMessage.showYes(message); return; } tIPViewModel._FaceObj.NAge = int.Parse(txtAge.Text.Trim()); } else { //MyMessage.showYes("人员年龄是必输项!"); MyMessage.showYes("人员年龄是必输项!"); return; } if (combSex.SelectedIndex != 0) { tIPViewModel._FaceObj.NSex = combSex.SelectedIndex; } else { //MyMessage.showYes("人员性别是必输项!"); MyMessage.showYes("人员性别是必输项!"); return; } //暂时没确定 if (combType.SelectedIndex != 0) { foreach (var basicinfo in BasicInfo.DefFaceObjType) { if (basicinfo.Description == tIPViewModel.Type[combType.SelectedIndex]) { tIPViewModel._FaceObj.NType = basicinfo.Type; // 类型 } } } else { //MyMessage.showYes("人员类型是必输项!"); MyMessage.showYes("人员类型是必输项!"); return; } tIPViewModel._FaceObj.TcRemarks = txtRemarks.Text.Trim(); #endregion tIPViewModel._FaceObj.Tmplate = new List <FaceObjTemplate>(); //遍历照片存放数组,必须添加至少一张照片 bool bIsPic = false; for (int i = 0; i < 5; i++) { if (strPhoto[i] != null) { bIsPic = true; break; } } if (!bIsPic) { //MyMessage.showYes("至少要一张照片才能注册成功"); MyMessage.showYes("至少要一张照片才能注册成功!"); return; } int nj = -1; for (int i = 0; i < 5; i++) { if (strPhoto[i] != null) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); string StringName = System.Guid.NewGuid().ToString(); StringName = StringName.Replace("-", ""); _FaceObjTemplate.TcUuid = StringName; _FaceObjTemplate.TcObjid = tIPViewModel._FaceObj.TcUuid; //判断前面是不是有空位置,有那么排到前面去 for (int j = 0; j < i; j++) { if (strPhoto[j] == null) { _FaceObjTemplate.NIndex = j; nj = j; break; } } if (_FaceObjTemplate.NIndex == 0) { if (nj == -1) { _FaceObjTemplate.NIndex = i; } else { _FaceObjTemplate.NIndex = nj; } } //时间 string strNow = DateTime.Now.ToString(); DateTime dt1 = Convert.ToDateTime(strNow); TimeSpan dt1Span = new TimeSpan(dt1.Ticks); DateTime dt2 = new DateTime(1970, 1, 1); TimeSpan dt2Span = new TimeSpan(dt2.Ticks); long longAddTemplateTime = Convert.ToInt64(dt1Span.TotalSeconds - dt2Span.TotalSeconds); _FaceObjTemplate.DTm = longAddTemplateTime;//模板时间 if (tIPViewModel._FaceObj.DTm == 0) { tIPViewModel._FaceObj.DTm = longAddTemplateTime; } if (_strPhotoMain != null) { if (_strPhotoMain.Equals(strPhoto[i])) { tIPViewModel._FaceObj.NMain_ftID = i + 1;//主照片ID } else { if (i == tIPViewModel._FaceObj.NMain_ftID - 1) { tIPViewModel._FaceObj.NMain_ftID = _FaceObjTemplate.NIndex + 1;//主照片ID } } } else { tIPViewModel._FaceObj.NMain_ftID = 0; } _FaceObjTemplate.Img = strPhoto[i]; tIPViewModel._FaceObj.Tmplate.Add(_FaceObjTemplate); if (nj != -1) { strPhoto[nj] = strPhoto[i]; strPhoto[i] = null; nj = -1; } } } //具体的操作(添加,修改) if (tIPViewModel.Title.Contains("添加")) { ListErrorInfo = thirft.AddFaceObj(tIPViewModel._FaceObj); } else { ListErrorInfo = thirft.ModifyFaceObj(tIPViewModel.Id, tIPViewModel._FaceObj); } //判断是否成功 if (ListErrorInfo.Count == 0)//判断成功,提示成功 { MyMessage.showYes("成功!"); this.Close(); } else//添加不成功,显示错误 { for (int j = 0; j < ListErrorInfo.Count; j++) { string strError = "添加模板ID:" + ListErrorInfo[j].ID + "失败,失败信息:" + ListErrorInfo[j].ErrCode; MyMessage.showYes(strError); } } } catch (Exception ex) { _WriteLog.WriteToLog("AddTemplate:btnRemove_Click", ex); return; } }
/// <summary> /// 确定按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDetermineAddTemplate_Click(object sender, RoutedEventArgs e) { List <ErrorInfo> ListErrorInfo; ThriftServiceNameSpace.ThriftService thirft = new ThriftServiceNameSpace.ThriftService(); try { /** * 姓名 * 性别 * 年龄 * 类型:普通、黑名单 * 备注 * 1张主照片 * 4张附属照片 均为模板照片,指向一个人 * **/ #region 验证 if (string.IsNullOrEmpty(txtName.Text.Trim())) { MyMessage.showYes("名称必填!"); return; } if (string.IsNullOrEmpty(txtAge.Text.Trim())) { MyMessage.showYes("年龄必填!"); return; } #endregion #region 添加输入项 tIPViewModel._FaceObj.TcUuid = guid; tIPViewModel._FaceObj.TcName = txtName.Text.Trim(); string message = _validationRule.intValidationRule(this.txtAge.Text.Trim()); if (message != "") { MyMessage.showYes(message); return; } tIPViewModel._FaceObj.NAge = int.Parse(txtAge.Text.Trim()); tIPViewModel._FaceObj.NSex = combSex.SelectedIndex; //暂时没确定 tIPViewModel._FaceObj.NType = (GlobalCache.FaceTypeList.Cast <STypeInfo>().FirstOrDefault(x => x.Description == tIPViewModel.Type[combType.SelectedIndex]) ?? new STypeInfo()).Type; tIPViewModel._FaceObj.TcRemarks = txtRemarks.Text.Trim(); #endregion tIPViewModel._FaceObj.Tmplate = new List <FaceObjTemplate>(); //遍历照片存放数组,必须添加至少一张照片 var isExistPhoto = templateData.FirstOrDefault(x => x != null) ?? null; if (isExistPhoto == null) { MyMessage.showYes("至少要一张照片才能注册成功!"); return; } int nj = -1; for (int i = 0; i < 5; i++) { if (templateData[i] != null) { FaceObjTemplate templateObj = new FaceObjTemplate(); templateObj.TcUuid = System.Guid.NewGuid().ToString().Replace("-", "");; templateObj.TcObjid = tIPViewModel._FaceObj.TcUuid; //判断前面是不是有空位置,有那么排到前面去 for (int j = 0; j < i; j++) { if (templateData[j] == null) { templateObj.NIndex = j; nj = j; break; } } if (templateObj.NIndex == 0) { if (nj == -1) { templateObj.NIndex = i; } else { templateObj.NIndex = nj; } } //时间 long addDateTime = DateTimeConvert.ToLongFromSubstract(DateTime.Now, new DateTime(1970, 1, 1)); templateObj.DTm = addDateTime;//模板时间 if (tIPViewModel._FaceObj.DTm == 0) { tIPViewModel._FaceObj.DTm = addDateTime; } if (_mainTemplateStream != null) { if (_mainTemplateStream.Equals(templateData[i])) { tIPViewModel._FaceObj.NMain_ftID = i;//主照片ID } else if (i == tIPViewModel._FaceObj.NMain_ftID) { tIPViewModel._FaceObj.NMain_ftID = templateObj.NIndex;//主照片ID } } else { tIPViewModel._FaceObj.NMain_ftID = 0;//主模板ID为 0 } templateObj.Img = templateData[i]; tIPViewModel._FaceObj.Tmplate.Add(templateObj);//Add Template to db.face_template/db.face_object if (nj != -1) { templateData[nj] = templateData[i]; templateData[i] = null; nj = -1; } } } //具体的操作(添加,修改) if (tIPViewModel.Title.Contains("添加")) { ListErrorInfo = thirft.AddFaceObj(tIPViewModel._FaceObj); } else { ListErrorInfo = thirft.ModifyFaceObj(tIPViewModel.Id, tIPViewModel._FaceObj); } //判断是否成功 if (ListErrorInfo.Count == 0)//判断成功,提示成功 { MyMessage.showYes("成功!"); this.Close(); } else//添加不成功,显示错误 { if ("Add Face To Compare Server Failed, Because img repeat".Equals(ListErrorInfo[0].ID)) { MyMessage.Show("模板照片已存在,请取消并重新添加模板"); return; } else { MyMessage.showYes("添加模板ID:" + ListErrorInfo[0].ID + "失败,\n失败信息:" + ListErrorInfo[0].ErrCode); return; } } } catch (Exception ex) { Logger <TempleteInfoPop> .Log.Error("AddTemplate:btnRemove_Click", ex); } }
private void StartExcelImport(object filePathObj) { string filePath = @"C:\Users\Tsu\Desktop\2个插件\测试.xls"; IWorkbook workbook = null; ISheet sheet = null; try { var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); if (filePath.IndexOf(".xlsx") > 0) // 2007版本 { workbook = new XSSFWorkbook(fs); } else if (filePath.IndexOf(".xls") > 0) // 2003版本 { workbook = new HSSFWorkbook(fs); } if (sheet == null) //取第一个sheet { sheet = workbook.GetSheetAt(0); } //excel总行数 int rowCount = sheet.LastRowNum; tIPViewModel.MaxLength = rowCount; var pictureList = sheet.GetAllPictureInfos(); for (int i = 2; i < rowCount; i++) { IRow curRow = sheet.GetRow(i); if (curRow.Cells.Count == 0) { Console.WriteLine("NO." + i + "行为空行!"); continue; } FaceObj _FaceObj = new FaceObj();//实例OrderInf,添加到新的窗口的list中 _FaceObj.Tmplate = new List <FaceObjTemplate>(); //人脸对象添加时间 DateTime dt0 = Convert.ToDateTime(DateTime.Now); TimeSpan dt0Span = new TimeSpan(dt0.Ticks); DateTime dt01 = new DateTime(1970, 1, 1); TimeSpan dt01Span = new TimeSpan(dt01.Ticks); long longDPTemplateStarTime0 = Convert.ToInt64(dt0Span.TotalSeconds - dt01Span.TotalSeconds); _FaceObj.DTm = longDPTemplateStarTime0; #region 读取excel 生成人脸对象 foreach (var item in ExcelColNo) { switch (ExcelColNo.IndexOf(item)) { //人脸uuid case 0: string StringName = System.Guid.NewGuid().ToString(); StringName = StringName.Replace("-", ""); _FaceObj.TcUuid = StringName; break; //姓名 case 1: if (item != 0) { _FaceObj.TcName = curRow.GetCell(item).ToString(); Console.WriteLine(i + _FaceObj.TcName); } else { _FaceObj.TcName = _FaceObj.TcUuid; } break; //人脸首选模板标识序号 case 2: _FaceObj.NMain_ftID = 0; break; //类型 case 3: if (item != 0) { _FaceObj.NType = 0; } break; //敏感等级 case 4: if (item != 0) { _FaceObj.NSST = Convert.ToInt32(curRow.GetCell(item).ToString()); } break; //额外信息 case 5: if (item != 0) { _FaceObj.NExten = Convert.ToInt32(curRow.GetCell(item).ToString()); } break; //性别 case 6: if (item != 0) { _FaceObj.NSex = 0; } break; //年龄 case 7: if (item != 0) { _FaceObj.NAge = Convert.ToInt32(curRow.GetCell(item).ToString()); } break; //备注 case 8: if (item != 0) { _FaceObj.TcRemarks = curRow.GetCell(item).ToString(); } break; //模板1 case 9: if (item != 0) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); var picture = GetPictureByRowCol(pictureList, i, item); if (picture != null) { _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.Tmplate.Last().Img = picture.PictureData; } } break; //模板2 case 10: if (item != 0) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); var picture = GetPictureByRowCol(pictureList, i, item); if (picture != null) { _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.Tmplate.Last().Img = picture.PictureData; } } break; //模板3 case 11: if (item != 0) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); var picture = GetPictureByRowCol(pictureList, i, item); if (picture != null) { _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.Tmplate.Last().Img = picture.PictureData; } } break; //模板4 case 12: if (item != 0) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); var picture = GetPictureByRowCol(pictureList, i, item); if (picture != null) { _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.Tmplate.Last().Img = picture.PictureData; } } break; //模板5 case 13: if (item != 0) { FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); var picture = GetPictureByRowCol(pictureList, i, item); if (picture != null) { _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.Tmplate.Last().Img = picture.PictureData; } } break; } } #endregion //异步上传人脸对象 while (true) { if (upingCount <= maxUpCount) { //Console.WriteLine("第" + i + "次运行"); AddFaceObjDelegate.BeginInvoke(_FaceObj, new AsyncCallback(PicHandle), _FaceObj); upingCount++; break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 读取图片生成人脸对象 /// </summary> /// <param name="i"></param> /// <param name="type">导入类型:0图片;1excel</param> public void ThreadImportPicIntoDb(int i, int type) { try { if (type == 0) { string sourceName = (filesPic[i].DirectoryName + "\\" + filesPic[i].Name); if (File.Exists(sourceName)) { #region FaceObj _FaceObj = new FaceObj(); //实例OrderInf,添加到新的窗口的list中 //人脸对象添加时间 DateTime dt0 = Convert.ToDateTime(DateTime.Now); TimeSpan dt0Span = new TimeSpan(dt0.Ticks); DateTime dt01 = new DateTime(1970, 1, 1); TimeSpan dt01Span = new TimeSpan(dt01.Ticks); long longDPTemplateStarTime0 = Convert.ToInt64(dt0Span.TotalSeconds - dt01Span.TotalSeconds); _FaceObj.DTm = longDPTemplateStarTime0; //生成人脸对象uuid //生成uuid string StringName = System.Guid.NewGuid().ToString(); StringName = StringName.Replace("-", ""); _FaceObj.TcUuid = StringName; //人脸名称 _FaceObj.TcName = filesPic[i].Name.Substring(0, filesPic[i].Name.Length - 4); _FaceObj.Tmplate = new List <FaceObjTemplate>(); FaceObjTemplate _FaceObjTemplate = new FaceObjTemplate(); _FaceObj.Tmplate.Add(_FaceObjTemplate); _FaceObj.NMain_ftID = 0; //设置主模板ID string strPath2 = sourceName; //获得文件地址 if (strPath2 != "") { _FaceObj.Tmplate[0].Img = System.IO.File.ReadAllBytes(strPath2); } //判断统一指定类型 if ((strSex == "全部" && strType == "请选择")) { _FaceObj.NSex = 0; _FaceObj.NType = 1; } else { if (strSex != "" && strType != "") { _FaceObj.NSex = tIPViewModel.SelectedSex; foreach (var basicinfo in GlobalCache.FaceTypeList.Cast <STypeInfo>()) { if (basicinfo.Description == tIPViewModel.Type[tIPViewModel.SelectedType]) { _FaceObj.NType = basicinfo.Type == 0 ? -1 : basicinfo.Type; } } } else { if (strSex != "")//如果指定了性别 { _FaceObj.NSex = tIPViewModel.SelectedSex; } if (strType != "")//如果指定了类型 { foreach (var basicinfo in GlobalCache.FaceTypeList.Cast <STypeInfo>()) { if (basicinfo.Description == tIPViewModel.Type[tIPViewModel.SelectedType]) { _FaceObj.NType = basicinfo.Type == 0 ? -1 : basicinfo.Type; } } } } } #endregion //补足模板中不足的字段 for (int k = 0; k < _FaceObj.Tmplate.Count; k++) { if (_FaceObj.Tmplate[k].Img != null)//判断模板照片存在 { //生成uuid StringName = System.Guid.NewGuid().ToString(); StringName = StringName.Replace("-", ""); _FaceObj.Tmplate[k].TcUuid = StringName; //所属FaceObj的uuid _FaceObj.Tmplate[k].TcObjid = _FaceObj.TcUuid; //模板序号 _FaceObj.Tmplate[k].NIndex = k; // 模板添加时间 DateTime dt1 = Convert.ToDateTime(DateTime.Now); TimeSpan dt1Span = new TimeSpan(dt1.Ticks); DateTime dt2 = new DateTime(1970, 1, 1); TimeSpan dt2Span = new TimeSpan(dt2.Ticks); long longDPTemplateStarTime = Convert.ToInt64(dt1Span.TotalSeconds - dt2Span.TotalSeconds); _FaceObj.Tmplate[k].DTm = longDPTemplateStarTime; } } while (true) { if (upingCount <= maxUpCount) { AddFaceObjDelegate.BeginInvoke(_FaceObj, new AsyncCallback(PicHandle), _FaceObj); upingCount++; break; } } } } } catch (Exception ex) { Logger <OperaExcel> .Log.Error("ThreadImportPicIntoDb", ex); return; } }
public void Read(TProtocol iprot) { iprot.IncrementRecursionDepth(); try { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.String) { TcUuid = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.String) { TcName = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.I32) { NMain_ftID = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.I32) { NType = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 5: if (field.Type == TType.I32) { NSST = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 6: if (field.Type == TType.I32) { NExten = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 7: if (field.Type == TType.I32) { NSex = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 8: if (field.Type == TType.I32) { NAge = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 9: if (field.Type == TType.I64) { DTm = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 10: if (field.Type == TType.String) { TcRemarks = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 11: if (field.Type == TType.List) { { Tmplate = new List <FaceObjTemplate>(); TList _list0 = iprot.ReadListBegin(); for (int _i1 = 0; _i1 < _list0.Count; ++_i1) { FaceObjTemplate _elem2; _elem2 = new FaceObjTemplate(); _elem2.Read(iprot); Tmplate.Add(_elem2); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); } finally { iprot.DecrementRecursionDepth(); } }