private void loadDataList() { mapImage = new Hashtable(); DirectoryInfo directory = new DirectoryInfo(Gobal.TRAIN_PATH); FileInfo[] files = directory.GetFiles("*0.jpg"); foreach (FileInfo f in files) { String sid = f.Name.Split('.')[0].Split('-')[0]; Image <Gray, Byte> trainingImage = new Image <Gray, Byte>(f.FullName).Convert <Gray, Byte>(); trainingImage = Process.Detector.PreProcess(trainingImage); UCResultItem ucResultItem = new UCResultItem(trainingImage, f.Name.Split('.')[0]); mapImage.Add(sid, ucResultItem); StackPanelMain.Children.Add(ucResultItem); } for (int i = 0; i < found.Length; i++) { if (found[i] != null) { if (found[i].Distance < double.MaxValue) { Student s = (Student)mapStudentData[i + ""]; UCResultItem item = (UCResultItem)mapImage[s.StudentID]; item.RPic.Source = Display.Bitmap.ToBitmapSource(found[i].Image); item.Name.Content = found[i].Distance; } } } }
private void loadData() { items = new List <UCResultItem>(); String currDatePath = Gobal.RESULT_PATH + "/" + cbResultDate.SelectedItem; DirectoryInfo directory = new DirectoryInfo(currDatePath); FileInfo[] files = directory.GetFiles("*.txt"); StackPanelMain.Children.Clear(); foreach (FileInfo f in files) { string[] lines = System.IO.File.ReadAllLines(currDatePath + "/" + f.Name); Image <Bgr, Byte> trainingImage = new Image <Bgr, Byte>(Gobal.TRAIN_PATH + "/" + f.Name.Split('.')[0] + "-0.jpg"); Image <Bgr, Byte> resultImage = new Image <Bgr, Byte>(currDatePath + "/" + f.Name.Split('.')[0] + ".jpg"); String text = lines[0]; String[] split = text.Split('\t'); // resultImage._EqualizeHist(); UCResultItem ucResultItem = new UCResultItem(trainingImage, resultImage, split[1] + " " + split[2] + " " + split[3]); StackPanelMain.Children.Add(ucResultItem); } }
void timer_Tick(object sender, EventArgs e) { try { currentFrame = capture.QueryFrame(); Image <Gray, Byte> gray = currentFrame.Convert <Gray, byte>(); faceDetected = Process.Detector.DetectFace(gray); double[] distance = new double[found.Length + 1]; List <DrawTextData> faceFound = new List <DrawTextData>(); faceObjects[0] = new List <FaceObject>(); for (int i = 0; i < faceDetected.Length; i++) { Image <Gray, Byte> face = gray.Copy(faceDetected[i]).Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC); face = Process.Detector.PreProcess(face); FaceRecognizer.PredictionResult tmp = recognizer.Who(face); FaceRecognizer.PredictionResult tmp2 = recognizer.Who(face.Copy().Flip(FLIP.HORIZONTAL).Convert <Gray, Byte>()); FaceRecognizer.PredictionResult who = tmp.Distance < tmp2.Distance ? tmp : tmp2; if (who.Label > -1) { FaceObject facObj = new FaceObject(faceDetected[i], face, who.Distance, who.Label, CurrentMillis.Millis + ""); facObj.Label = who.Label; facObj.Distance = who.Distance; facObj.Rect = faceDetected[i]; facObj.DateTime = CurrentMillis.Millis + ""; faceObjects[0].Add(facObj); } } if (faceObjects[1] != null) { foreach (FaceObject fobj1 in faceObjects[1]) { int idxMin = -1; double d2pMin = Double.MaxValue; for (int i = 0; i < faceObjects[0].Count; i++) { double d2p = Math.Sqrt((fobj1.Rect.X - faceObjects[0][i].Rect.X) * (fobj1.Rect.X - faceObjects[0][i].Rect.X) + (fobj1.Rect.Y - faceObjects[0][i].Rect.Y) * (fobj1.Rect.Y - faceObjects[0][i].Rect.Y)); if (d2p < d2pMin) { d2pMin = d2p; idxMin = i; } } Student s = (Student)mapStudentData[fobj1.Label + ""]; String text = s.ID + " " + s.StudentID + " " + s.Name + " " + s.LastName; if (d2pMin > 50f) { if (found[fobj1.Label] != null) { if (found[fobj1.Label].Distance > fobj1.Distance) { found[fobj1.Label] = new Found(fobj1.Distance, fobj1.Image.Clone()); Image <Gray, byte> test = found[fobj1.Label].Image.Clone(); String imagePath = currDatePath + s.StudentID + ".jpg"; Display.Bitmap.SaveToJpeg(found[fobj1.Label].Image.Clone().Convert <Gray, Byte>(), imagePath); using (System.IO.StreamWriter file = new System.IO.StreamWriter(currDatePath + s.StudentID + ".txt")) { String textOut = s.ID + "\t" + s.StudentID + "\t" + s.Name + "\t" + s.LastName + "\t" + fobj1.Distance; file.WriteLine(textOut); } } } } else { if (faceObjects[0][idxMin].Distance > fobj1.Distance) { faceObjects[0][idxMin].Distance = fobj1.Distance; faceObjects[0][idxMin].Label = fobj1.Label; faceObjects[0][idxMin].Image = fobj1.Image.Clone(); } faceObjects[0][idxMin].DateTime = fobj1.DateTime; } distance[fobj1.Label] = fobj1.Distance; faceFound.Add(new DrawTextData(fobj1.Rect, text + " " + fobj1.Distance)); } } // StackPanelMain.Children.Clear(); for (int i = 0; i < found.Length; i++) { if (found[i] != null) { if (found[i].Distance < double.MaxValue) { Student s = (Student)mapStudentData[i + ""]; UCResultItem item = (UCResultItem)mapImage[s.StudentID]; item.RPic.Source = Display.Bitmap.ToBitmapSource(found[i].Image); item.Name.Content = found[i].Distance + " " + distance[i]; mark(i); //StackPanelMain.Children[2] // StackPanelMain.Children.Add(item); } } } faceObjects[1] = new List <FaceObject>(faceObjects[0]); DispFrame.Source = Display.Bitmap.ToBitmapSource(Process.Detector.DrawFace(currentFrame.Clone(), faceDetected, (faceFound.Count > 0)), faceFound); } catch { } }