public DetectFaceInfo(DetectResult detectResult, string path) { string[] strings = path.Split('_'); if (detectResult.face.Count>0) { Face face = detectResult.face.SingleOrDefault(); Age = face.attribute.age.value; AgeRange = face.attribute.age.range; Gender = face.attribute.gender.value; GenderConfidence = face.attribute.gender.confidence; Race = face.attribute.race.value; RaceConfidence = face.attribute.race.confidence; } // long ticks = long.Parse(strings[0]); // TimeSpan timeSpan=new TimeSpan(ticks); // DateTime CentryBegin = new DateTime(2001,1,1); //// Time = CentryBegin.Add(timeSpan); //// TrackingID = Int32.Parse(strings[1]); // int temp = Int32.Parse(strings[2]); //// TotalStayTime = temp/DepthImageFramePerSecond; // if (detectResult.face.Count>0) // { // // FaceAttribute face = detectResult.face.FirstOrDefault().attribute; // } }
private void detectFace(string path) { DetectResult detect = new DetectResult(); DetectResult res = fs.Detection_DetectImg(path); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); bi.EndInit(); WriteableBitmap wb = new WriteableBitmap(bi); List<Face> faceList = new List<Face>(); for (int i = 0; i < res.face.Count; i++) { faceList.Add(res.face[i]); Int32Rect rect = new Int32Rect(maxInt((Int32)(res.face[i].center.x * wb.Width / 100.0 - res.face[i].width * wb.Width / 200.0), 0), maxInt((int)(res.face[i].center.y * wb.Height / 100.0 - res.face[i].height * wb.Height / 200.0), 0), (int)(res.face[i].width * wb.Width / 100.0), (int)((res.face[i].height * wb.Height) / 100.0)); byte[] ColorData = { 0, 0, 255, 100 }; // B G R for (int j = 0; j < rect.Width; j++) { Int32Rect rect1 = new Int32Rect( j + rect.X, rect.Y, 1, 1); wb.WritePixels(rect1, ColorData, 4, 0); Int32Rect rect2 = new Int32Rect( j + rect.X, rect.Y + rect.Height, 1, 1); wb.WritePixels(rect2, ColorData, 4, 0); } for (int j = 0; j < rect.Height; j++) { Int32Rect rect1 = new Int32Rect( rect.X, j + rect.Y, 1, 1); wb.WritePixels(rect1, ColorData, 4, 0); Int32Rect rect2 = new Int32Rect( rect.X + rect.Width, j + rect.Y, 1, 1); wb.WritePixels(rect2, ColorData, 4, 0); } } var pngE1 = new PngBitmapEncoder(); pngE1.Frames.Add(BitmapFrame.Create(wb)); using (Stream stream = File.Create(path + ".jpg")) { pngE1.Save(stream); } // Insert code to set properties and fields of the object. XmlSerializer mySerializer = new XmlSerializer(typeof(List<Face>)); // To write to a file, create a StreamWriter object. StreamWriter myWriter = new StreamWriter("detectResult.xml", true); mySerializer.Serialize(myWriter, faceList); myWriter.Close(); }
private void DefaultStage(DetectResult detectResult) { if (detectResult.face.Count == 1) { VerifyResult person = fs.Recognition_VerifyByName(detectResult.face[0].face_id, userName.Text); status.Content = "Hello " + userName.Text + ", What would you like to do?"; if (person == null) { PersonBasicInfo info = fs.Person_Create(userName.Text, detectResult.face[0].face_id); AsyncResult a = fs.Train_VerifyById(info.person_id); } else { if (!person.is_same_person) status.Content = "NO! You are not " + userName.Text; else { lockFile.IsEnabled = true; UnlockFile.IsEnabled = true; Increase.IsEnabled = true; } } } else { status.Content = "No face detected"; } }
private void AddFaceStage(DetectResult detectResult) { if (detectResult.face.Count != 1) { System.Windows.MessageBox.Show("No face detected, or more than one faces detected"); return; } //perform add face to person ManageResult result = fs.Person_AddFaceByName(userName.Text, detectResult.face[0].face_id); if (result == null) return; if (result.success) { fs.Train_VerifyByName(userName.Text); System.Windows.MessageBox.Show("Face Added"); } }
private void DetectImages(List<string> fileNames) { foreach (var fileName in fileNames) { DetectResult detectResult = new DetectResult(); detectResult = faceService.Detection_DetectImg(savePath + "\\" + fileName); DetectFaceInfo detectFaceInfo = new DetectFaceInfo(detectResult, fileName); DetectFaceInfos.Add(detectFaceInfo); MoveFile(savePath + "\\" + fileName); SaveDataToDB(detectResult, fileName); } }
private void SaveDataToDB(DetectResult detectResult, string fileName) { using (var session = DocumentStore.OpenSession()) { string[] st = fileName.Split('_'); DetectFaceInfo detectFaceInfo = session.Load<DetectFaceInfo>(st[0]); if (detectFaceInfo != null) { if (detectFaceInfo.Race == null) { if (detectResult.face.Count > 0) { Face face = detectResult.face.SingleOrDefault(); detectFaceInfo.Age = face.attribute.age.value; detectFaceInfo.AgeRange = face.attribute.age.range; detectFaceInfo.Gender = face.attribute.gender.value; detectFaceInfo.GenderConfidence = face.attribute.gender.confidence; detectFaceInfo.Race = face.attribute.race.value; detectFaceInfo.RaceConfidence = face.attribute.race.confidence; } } session.Store(detectFaceInfo); session.SaveChanges(); } } }