Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        public double DeltaRows(OCVGridDefinition grid)
        {
            double result = 0;

            for (int r = 0; r < grid.Rows; r++)
            {
                int location = grid.RowLocation(r);
                int line0    = 0;
                int line1    = HorizontalLines.Count - 1;
                while (line0 < line1 - 1 && HorizontalLines[line0 + 1].GetSummaryLine().GetLocation() < location)
                {
                    line0++;
                }
                while (line1 > line0 + 1 && (line1 == HorizontalLines.Count - 1 || HorizontalLines[line1 + 1].GetSummaryLine().GetLocation() > location))
                {
                    line1--;
                }
                result += Math.Min(Math.Abs(location - HorizontalLines[line0].GetSummaryLine().GetLocation()),
                                   Math.Abs(location - HorizontalLines[line1].GetSummaryLine().GetLocation()));
            }
            return(result / grid.Rows);
        }
 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));
 }