public double DeltaCols(OCVGridDefinition grid) { double result = 0; using (StreamWriter sw = new StreamWriter("deltas.log")) { for (int c = 0; c < grid.Cols; c++) { int location = grid.ColLocation(c); sw.Write("c: {0} location: {1} ", c, location); int line0 = 0; int line1 = VerticalLines.Count - 1; while (line0 < line1 - 1 && VerticalLines[line0 + 1].GetSummaryLine().GetLocation() < location) { line0++; } while (line1 > line0 + 1 && (line1 == VerticalLines.Count - 1 || VerticalLines[line1 + 1].GetSummaryLine().GetLocation() > location)) { line1--; } sw.Write(" line0: {0} [{1}] line1: {2} [{3}] ", line0, VerticalLines[line0].GetSummaryLine().GetLocation(), line1, VerticalLines[line1].GetSummaryLine().GetLocation()); double delt = Math.Min(Math.Abs(location - VerticalLines[line0].GetSummaryLine().GetLocation()), Math.Abs(location - VerticalLines[line1].GetSummaryLine().GetLocation())); sw.WriteLine(" delta = {0} ", delt); result += delt; } } return(result / grid.Cols); }
private int[,] FindColValues(Matrix <byte> matrix, OCVGridDefinition gridDef, int testWidth) { int[,] result = new int[gridDef.Rows, gridDef.Cols]; int minVal, maxVal; for (int c = 0; c < gridDef.Cols; c++) { int colLoc = (int)(gridDef.ColLocation(c) + gridDef.ColSize * 0.5); result[0, c] = EXTERNALBORDER; for (int r = 1; r < gridDef.Rows; r++) { int loc = gridDef.RowLocation(r); minVal = Int32.MaxValue; maxVal = Int32.MinValue; for (int row = loc - testWidth; row < loc + testWidth; row++) { if (row < 0 || row >= matrix.Rows) { continue; } byte value = matrix.Data[row, colLoc]; if (value < minVal) { minVal = value; } if (value > maxVal) { maxVal = value; } } result[r, c] = maxVal - minVal; } } return(result); }
private void DrawGrid(Image <Bgr, Byte> image, OCVGridDefinition gridDef, Bgr color) { for (int r = 0; r <= gridDef.Rows; r++) { image.Draw(new LineSegment2D(new Point(gridDef.TopLeft.X, gridDef.RowLocation(r)), new Point(gridDef.TopLeft.X + gridDef.Width, gridDef.RowLocation(r))), color, 2); } for (int c = 0; c <= gridDef.Cols; c++) { image.Draw(new LineSegment2D(new Point(gridDef.ColLocation(c), gridDef.TopLeft.Y), new Point(gridDef.ColLocation(c), gridDef.TopLeft.Y + gridDef.Height)), color, 2); } image.Draw(new Rectangle(gridDef.TopLeft.X, gridDef.TopLeft.Y, gridDef.Width, gridDef.Height), color, 2); }
private int[,] FindRowValues(Matrix <byte> matrix, OCVGridDefinition gridDef, int testWidth) { int[,] result = new int[gridDef.Rows, gridDef.Cols]; int minVal, maxVal; for (int r = 0; r < gridDef.Rows; r++) { int rowLoc = (int)(gridDef.RowLocation(r) + gridDef.RowSize * 0.5); for (int c = 1; c < gridDef.Cols; c++) { result[r, 0] = EXTERNALBORDER; int loc = gridDef.ColLocation(c); minVal = Int32.MaxValue; maxVal = Int32.MinValue; for (int col = loc - testWidth; col < loc + testWidth; col++) { if (col < 0 || col >= matrix.Cols) { continue; } byte value = matrix.Data[rowLoc, col]; if (value < minVal) { minVal = value; } if (value > maxVal) { maxVal = value; } } result[r, c] = maxVal - minVal; } } return(result); }
private Rectangle gridRect(OCVGridDefinition gridDef, int row, int col) { return(new Rectangle((int)gridDef.ColLocation(col), (int)gridDef.RowLocation(row), (int)gridDef.ColSize, (int)gridDef.RowSize)); }