/// <summary> /// 匹配 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void MatchImage() { if (ImagesFeatureList.Count == 0) { MessageBox.Show("请注册人脸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (ImageFeature == IntPtr.Zero) { if (FRC.FIView._faceIdentificationImageBox.Source == null) { MessageBox.Show("请选择识别图!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("比对失败,识别图未提取到特征值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } //标记已经做了匹配比对,在开启视频的时候要清除比对结果 isCompare = true; float compareSimilarity = 0f; int compareNum = -1; AppendText(string.Format("------------------------------开始比对,时间:{0}------------------------------\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ms"))); ImagesFeatureList.Clear(); foreach (var item in FRC.FRVM.PIVMList) { ImagesFeatureList.Add(item.FaceCharacteristics); } for (int i = 0; i < ImagesFeatureList.Count; i++) { IntPtr feature = ImagesFeatureList[i]; float similarity = 0f; int ret = ASFFunctions.ASFFaceFeatureCompare(pImageEngine, ImageFeature, feature, ref similarity); //增加异常值处理 if (similarity.ToString().IndexOf("E") > -1) { similarity = 0f; } AppendText(string.Format("与{0}号比对结果:{1}\r\n", i, similarity)); //选择最合适的图片 if (similarity > compareSimilarity && similarity >= threshold) { compareSimilarity = similarity; compareNum = i; } //_imageList.Items[i].Text = string.Format("{0}号({1})", i, similarity); } FRC.FIVM.PersonInfoUC.DataContext = FRC.FRVM.PIVMList.SingleOrDefault(x => x.FaceCharacteristics == ImagesFeatureList[compareNum]); if (compareSimilarity > 0) { //_lblCompareInfo.Text = " " + compareNum + "号," + compareSimilarity; } AppendText(string.Format("------------------------------比对结束,时间:{0}------------------------------\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ms"))); }
/// <summary> /// 导入照片录入 /// </summary> /// <param name="IsOfflineRecord">是否为本地导入</param> public void ImportImgesFun(bool IsOfflineRecord) { lock (locker) { List <string> imagePathListTemp = ImportImages(IsOfflineRecord); if (imagePathListTemp.Count <= 0) { return; } FRC.PIVM.NaturalSourceImage = imagePathListTemp[0]; var numStart = ImagePathList.Count; int isGoodImage = 0; //人脸检测以及提取人脸特征 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { //人脸检测和剪裁 for (int i = 0; i < imagePathListTemp.Count; i++) { Image image = UtilTool.ReadImageFromFile(imagePathListTemp[i]); if (image == null) { continue; } if (image.Width > 1536 || image.Height > 1536) { image = UtilTool.ScaleImage(image, 1536, 1536); } if (image == null) { continue; } if (image.Width % 4 != 0) { image = UtilTool.ScaleImage(image, image.Width - (image.Width % 4), image.Height); } //人脸检测 ASF_MultiFaceInfo multiFaceInfo = UtilToolFace.DetectFace(pImageEngine, image); //判断检测结果 if (multiFaceInfo.faceNum > 0) { ImagePathList.Add(imagePathListTemp[i]); MRECT rect = UtilToolMemory.PtrToStructure <MRECT>(multiFaceInfo.faceRects); image = UtilTool.CutImage(image, rect.left, rect.top, rect.right, rect.bottom); } else { if (image != null) { image.Dispose(); } continue; } //显示人脸 FRC.MainView.Dispatcher.Invoke(new Action(delegate { if (image == null) { image = UtilTool.ReadImageFromFile(imagePathListTemp[i]); if (image.Width > 1536 || image.Height > 1536) { image = UtilTool.ScaleImage(image, 1536, 1536); } } //_imageLists.Images.Add(imagePathListTemp[i], image); //_imageList.Items.Add((numStart + isGoodImage) + "号", imagePathListTemp[i]); isGoodImage += 1; if (image != null) { image.Dispose(); } })); } //提取人脸特征 for (int i = numStart; i < ImagePathList.Count; i++) { ASF_SingleFaceInfo singleFaceInfo = new ASF_SingleFaceInfo(); Image image = UtilTool.ReadImageFromFile(ImagePathList[i]); if (image == null) { continue; } IntPtr feature = UtilToolFace.ExtractFaceFeature(pImageEngine, image, out singleFaceInfo); FRC.PIVM.FaceCharacteristics = feature; FRC.MainView.Dispatcher.Invoke(new Action(delegate { if (singleFaceInfo.faceRect.left == 0 && singleFaceInfo.faceRect.right == 0) { AppendText(string.Format("{0}号未检测到人脸\r\n", i)); } else { AppendText(string.Format("已提取{0}号人脸特征值,[left:{1},right:{2},top:{3},bottom:{4},orient:{5}]\r\n", i, singleFaceInfo.faceRect.left, singleFaceInfo.faceRect.right, singleFaceInfo.faceRect.top, singleFaceInfo.faceRect.bottom, singleFaceInfo.faceOrient)); ImagesFeatureList.Add(feature); } })); if (image != null) { image.Dispose(); } } FRC.MainView.Dispatcher.Invoke(new Action(delegate { FRC.MainVM.IsCameraEnable = true; //FRC.MainVM.IsPGBtnEnable = true; FRC.MainVM.IsSIBtnEnable = true; //FRC.MainVM.IsPGIBtnEnable = true; FRC.MainVM.IsSIIBtnEnable = true; })); })); //保存个人信息数据 //FRC.UploadFaceRecord(); } }