internal void Add(FaceFaceSimilarUnit faceRespondent) { faceRespondent.Size = new System.Drawing.Size(155, 179); faceRespondent.Width = this.Width - 10; faceRespondent.Height = 50; flowLayoutPanel1.Controls.Add(faceRespondent); }
private async Task NhanDien() { gFaceDetection.Text = "Face Detection ( FD ) đang nhận diện"; flowLayoutPanel2.Controls.Clear(); Confidence = Properties.Settings.Default.Confidence; if (FacePhoto.Image == null) { OpenFileDialogToPickImage(); } if (FacePhoto.Image == null) { gFaceDetection.Text = "Face Detection ( FD )"; return; } try { var ms = new MemoryStream(); FacePhoto.Image.Save(ms, ImageFormat.Png); var m = Serializer.Compress(ms); // If you're going to read from the stream, you may need to reset the position to the start ms.Position = 0; var watch = System.Diagnostics.Stopwatch.StartNew(); // the code that you want to measure comes here WriteLog(string.Format("Resquest DetectAsync")); var faces = await faceServiceClient.DetectAsync(m); watch.Stop(); WriteLog(string.Format("Response: Success. Detected {0} face(s) in {1} seconds", faces.Length, watch.Elapsed.TotalSeconds)); var personSimilarResultFace = new PersonSimilarResults(); flowLayoutPanel2.Controls.Clear(); foreach (var f in faces) { var faceId = f.FaceId; WriteLog(String.Format("Request: Finding similar faces in Face Match Mode for face {0}", faceId)); foreach (DataRow row in dtFaceList.Rows) { try { var personSimilarResults = await faceServiceClient.FindSimilarAsync(faceId, row.Item("faceListId"), FindSimilarMatchMode.matchFace, 4); foreach (var personSimilarResult in personSimilarResults) { if (personSimilarResult.Confidence >= Confidence) { personSimilarResultFace.Add(personSimilarResult.PersistedFaceId, personSimilarResult.Confidence); } } WriteLog(String.Format("Response: Success FindSimilarAsync {0}- {1}", faceId, row.Item("faceListId"))); } catch (FaceAPIException ex) { WriteLog(String.Format("Error FindSimilarAsync {0}- {1}:{2}", faceId, row.Item("faceListId"), ex.ErrorMessage)); } } } if (personSimilarResultFace.Data.Count == 0) { WriteLog(String.Format("Không tìm thấy khuôn mặt giống khuôn mặt đáp viên {0}", txtName.Text)); MessageBox.Show(String.Format("Không tìm thấy khuôn mặt giống khuôn mặt đáp viên {0}", txtName.Text)); gFaceDetection.Text = "Face Detection ( FD )"; return; } else { //MessageBox.Show( } var items = from pair in personSimilarResultFace.Data orderby pair.Value ascending select pair; var query = new DataAccess.RequestCollection(); string ids = ""; foreach (KeyValuePair <string, double> item in items) { ids += item.Key + ","; } query = DataAccess.DataQuery.Create("KadenceDB", "ws_FaceList_List", new { FaceIDs = ids }); var ds = this.Services.Execute(query); if (ds == null) { MessageBox.Show(Services.LastError); return; } foreach (DataRow row in ds.FirstTable().Rows) { var faceRespondent = new FaceFaceSimilarUnit(); faceRespondent.Conf = personSimilarResultFace.Data[row.Item("FaceID")]; faceRespondent.ProjectNameFullName = row.Item("ProjectNo") + "_" + row.Item("FullName"); byte[] byteImage = Convert.FromBase64String(row.Item("Image")); Image imageProfile; using (MemoryStream memorysteam = new MemoryStream(byteImage)) { imageProfile = Image.FromStream(memorysteam); } faceRespondent.ImageRespondent = imageProfile; faceRespondent.Height = flowLayoutPanel2.Height - 10; faceRespondent.Width = faceRespondent.Height; flowLayoutPanel2.Controls.Add(faceRespondent); } UI.ShowError(String.Format("Đã tìm thấy {1} khuôn mặt giống khuôn mặt đáp viên {0}", txtName.Text, ds.FirstTable().Rows.Count)); } catch (FaceAPIException ex) { MessageBox.Show(ex.Message); gFaceDetection.Text = "Face Detection ( FD )"; return; } gFaceDetection.Text = "Face Detection ( FD )"; }