public void TestMethod3() { Face.Aligner aligner = new Aligner("models\\pd_2_00_pts5.dat"); Face.Detector detector = new Detector("models\\fd_2_00.dat"); Face.Recognizer recognizer = new Recognizer("models\\fr_2_10.dat"); Stopwatch sw = new Stopwatch(); int error_cnt = 0; int no_face_error = 0; string base_path = "E:\\Downloads\\test_photo"; for (int i = 1; i <= 716; i++) { sw.Restart(); string file_name_1 = string.Format("{0}\\{1:D4}\\01.jpg", base_path, i); string file_name_2 = string.Format("{0}\\{1:D4}\\02.jpg", base_path, i); string file_name_3 = string.Format("{0}\\{1:D4}\\03.jpg", base_path, i); if (!new FileInfo(file_name_1).Exists) { continue; } if (!new FileInfo(file_name_2).Exists) { continue; } if (!new FileInfo(file_name_3).Exists) { continue; } Bitmap bmp1 = (Bitmap)Bitmap.FromFile(file_name_1); Bitmap bmp2 = (Bitmap)Bitmap.FromFile(file_name_2); Bitmap bmp3 = (Bitmap)Bitmap.FromFile(file_name_3); List <Rectangle> faces1 = detector.Detect(bmp1); List <Rectangle> faces2 = detector.Detect(bmp2); List <Rectangle> faces3 = detector.Detect(bmp3); if (faces1.Count < 1) { no_face_error++; continue; } if (faces2.Count < 1) { no_face_error++; continue; } if (faces3.Count < 1) { no_face_error++; continue; } List <PointF> pts1 = aligner.Align(bmp1, faces1[0]); List <PointF> pts2 = aligner.Align(bmp2, faces2[0]); List <PointF> pts3 = aligner.Align(bmp3, faces3[0]); double s1 = recognizer.Verify(bmp1, pts1, bmp2, pts2); double s2 = recognizer.Verify(bmp1, pts1, bmp3, pts3); double s3 = recognizer.Verify(bmp2, pts2, bmp3, pts3); sw.Stop(); if (s1 < 0.7) { error_cnt++; } if (s2 < 0.7) { error_cnt++; } if (s3 < 0.7) { error_cnt++; } Console.WriteLine("person:" + i + "\t time:" + sw.ElapsedMilliseconds); } Console.WriteLine("total error:" + error_cnt); Console.WriteLine("no_face error:" + no_face_error); }
public void TestMethod2() { Bitmap bmp1 = (Bitmap)Bitmap.FromFile("1.png"); Face.Aligner aligner = new Aligner("models\\pd_2_00_pts5.dat"); Face.Detector detector = new Detector("models\\fd_2_00.dat"); Face.Recognizer recognizer = new Recognizer("models\\fr_2_10.dat"); Stopwatch sw = new Stopwatch(); sw.Start(); List <Rectangle> faces1 = detector.Detect(bmp1); List <Rectangle> faces2 = detector.Detect(bmp1); sw.Stop(); long detect = sw.ElapsedMilliseconds; sw.Restart(); List <PointF> pt1 = aligner.Align(bmp1, faces1[0]); List <PointF> pt2 = aligner.Align(bmp1, faces2[1]); sw.Stop(); long align = sw.ElapsedMilliseconds; sw.Restart(); long idx1 = recognizer.Register(bmp1, pt1); long idx2 = recognizer.Register(bmp1, pt2); sw.Stop(); long register = sw.ElapsedMilliseconds; sw.Restart(); float similarity = 0; long idx = recognizer.Identify(bmp1, pt2, ref similarity); sw.Stop(); long identify = sw.ElapsedMilliseconds; sw.Restart(); double s = recognizer.Verify(bmp1, pt1, bmp1, pt2); sw.Stop(); long verify = sw.ElapsedMilliseconds; for (int i = 0; i < faces1.Count; i++) { Console.WriteLine(faces1[i].X + "\t" + faces1[i].Y + "\t" + faces1[i].Width + "\t" + faces1[i].Height); } Console.WriteLine(s); Console.WriteLine("detect:" + detect); Console.WriteLine("align:" + align); Console.WriteLine("verify:" + verify); Console.WriteLine("register:" + register); Console.WriteLine("identify:" + identify); Console.WriteLine("idx1:" + idx1); Console.WriteLine("idx2:" + idx2); Console.WriteLine("identified idx:" + idx); }
public static List <Segment> Render(TableRendererContext context, List <int> columnWidths) { // Can't render the table? if (context.TableWidth <= 0 || context.TableWidth > context.MaxWidth || columnWidths.Any(c => c <= 0)) { return(new List <Segment>(new[] { new Segment("…", context.BorderStyle ?? Style.Plain) })); } var result = new List <Segment>(); result.AddRange(RenderAnnotation(context, context.Title, _defaultHeadingStyle)); // Iterate all rows foreach (var(index, isFirstRow, isLastRow, row) in context.Rows.Enumerate()) { var cellHeight = 1; // Get the list of cells for the row and calculate the cell height var cells = new List <List <SegmentLine> >(); foreach (var(columnIndex, _, _, (rowWidth, cell)) in columnWidths.Zip(row).Enumerate()) { var justification = context.Columns[columnIndex].Alignment; var childContext = context.Options.WithJustification(justification); var lines = Segment.SplitLines(cell.Render(childContext, rowWidth)); cellHeight = Math.Max(cellHeight, lines.Count); cells.Add(lines); } // Show top of header? if (isFirstRow && context.ShowBorder) { var separator = Aligner.Align(context.Border.GetColumnRow(TablePart.Top, columnWidths, context.Columns), context.Alignment, context.MaxWidth); result.Add(new Segment(separator, context.BorderStyle)); result.Add(Segment.LineBreak); } // Show footer separator? if (context.ShowFooters && isLastRow && context.ShowBorder && context.HasFooters) { var textBorder = context.Border.GetColumnRow(TablePart.FooterSeparator, columnWidths, context.Columns); if (!string.IsNullOrEmpty(textBorder)) { var separator = Aligner.Align(textBorder, context.Alignment, context.MaxWidth); result.Add(new Segment(separator, context.BorderStyle)); result.Add(Segment.LineBreak); } } // Make cells the same shape cells = Segment.MakeSameHeight(cellHeight, cells); // Iterate through each cell row foreach (var cellRowIndex in Enumerable.Range(0, cellHeight)) { var rowResult = new List <Segment>(); foreach (var(cellIndex, isFirstCell, isLastCell, cell) in cells.Enumerate()) { if (isFirstCell && context.ShowBorder) { // Show left column edge var part = isFirstRow && context.ShowHeaders ? TableBorderPart.HeaderLeft : TableBorderPart.CellLeft; rowResult.Add(new Segment(context.Border.GetPart(part), context.BorderStyle)); } // Pad column on left side. if (context.ShowBorder || context.IsGrid) { var leftPadding = context.Columns[cellIndex].Padding.GetLeftSafe(); if (leftPadding > 0) { rowResult.Add(new Segment(new string(' ', leftPadding))); } } // Add content rowResult.AddRange(cell[cellRowIndex]); // Pad cell content right var length = cell[cellRowIndex].Sum(segment => segment.CellCount()); if (length < columnWidths[cellIndex]) { rowResult.Add(new Segment(new string(' ', columnWidths[cellIndex] - length))); } // Pad column on the right side if (context.ShowBorder || (context.HideBorder && !isLastCell) || (context.HideBorder && isLastCell && context.IsGrid && context.PadRightCell)) { var rightPadding = context.Columns[cellIndex].Padding.GetRightSafe(); if (rightPadding > 0) { rowResult.Add(new Segment(new string(' ', rightPadding))); } } if (isLastCell && context.ShowBorder) { // Add right column edge var part = isFirstRow && context.ShowHeaders ? TableBorderPart.HeaderRight : TableBorderPart.CellRight; rowResult.Add(new Segment(context.Border.GetPart(part), context.BorderStyle)); } else if (context.ShowBorder) { // Add column separator var part = isFirstRow && context.ShowHeaders ? TableBorderPart.HeaderSeparator : TableBorderPart.CellSeparator; rowResult.Add(new Segment(context.Border.GetPart(part), context.BorderStyle)); } } // Align the row result. Aligner.Align(rowResult, context.Alignment, context.MaxWidth); // Is the row larger than the allowed max width? if (Segment.CellCount(rowResult) > context.MaxWidth) { result.AddRange(Segment.Truncate(rowResult, context.MaxWidth)); } else { result.AddRange(rowResult); } result.Add(Segment.LineBreak); } // Show header separator? if (isFirstRow && context.ShowBorder && context.ShowHeaders && context.HasRows) { var separator = Aligner.Align(context.Border.GetColumnRow(TablePart.HeaderSeparator, columnWidths, context.Columns), context.Alignment, context.MaxWidth); result.Add(new Segment(separator, context.BorderStyle)); result.Add(Segment.LineBreak); } // Show bottom of footer? if (isLastRow && context.ShowBorder) { var separator = Aligner.Align(context.Border.GetColumnRow(TablePart.Bottom, columnWidths, context.Columns), context.Alignment, context.MaxWidth); result.Add(new Segment(separator, context.BorderStyle)); result.Add(Segment.LineBreak); } } result.AddRange(RenderAnnotation(context, context.Caption, _defaultCaptionStyle)); return(result); }