Пример #1
0
 public bool AddLine(OCVLineData line)
 {
     if (!IsInRange(line))
     {
         return(false);
     }
     Lines.Add(line);
     ReCompute();
     Sort();
     return(true);
 }
Пример #2
0
 public bool IsInRange(OCVLineData line)
 {
     if (!OCVConst.IsEqualValue(line.Line.Direction.X, Direction.X) && OCVConst.IsEqualValue(line.Line.Direction.Y, Direction.Y))
     {
         return(false);
     }
     else
     {
         return(GetLocation(line) <= maxRange && GetLocation(line) >= minRange);
     }
 }
Пример #3
0
 public double VerticalDistance(OCVLineData line2)
 {
     if (this.IsHorizontal() && line2.IsHorizontal())
     {
         return(Math.Abs(GetY() - line2.GetY()));
     }
     else
     {
         return(-1);
     }
 }
Пример #4
0
 public OCVGridData(LineSegment2D[] lines)
 {
     HorizontalLines = new List <OCVLineData>();
     VerticalLines   = new List <OCVLineData>();
     foreach (LineSegment2D line in lines)
     {
         if (line.Length < OCVConst.MinimalLineLength)
         {
             continue;
         }
         OCVLineData newData = new OCVLineData(line);
         if (newData.IsHorizontal())
         {
             HorizontalLines.Add(newData);
         }
         else if (newData.IsVertical())
         {
             VerticalLines.Add(newData);
         }
     }
     HorizontalLines.Sort(new OCVHorizontalLineDataSorter());
     VerticalLines.Sort(new OCVVerticalLineDataSorter());
 }
Пример #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            button1_Click(this, e);
            UMat edges = FindEdges();

            LineSegment2D[] lines = FindLines(edges);

            foreach (LineSegment2D line in lines)
            {
                lineImage.Draw(line, new Bgr(Color.LightGreen), 2);
            }
            pictureBox2.Image = lineImage.Bitmap;

            using (StreamWriter sw = new StreamWriter("lines0.dmp"))
            {
                foreach (LineSegment2D line in lines)
                {
                    if (line.Length > 10)
                    {
                        sw.WriteLine("line: (direction) {0} (P1) {1}  (P2) {2}   len: {3}", xyS(line.Direction.X, line.Direction.Y), xyS(line.P1.X, line.P1.Y), xyS(line.P2.X, line.P2.Y), line.Length);
                    }
                    else if (line.Length > 0)
                    {
                        sw.WriteLine("lijntje: (direction) {0} (P1) {1}  (P2) {2}   len: {3}", xyS(line.Direction.X, line.Direction.Y), xyS(line.P1.X, line.P1.Y), xyS(line.P2.X, line.P2.Y), line.Length);
                    }
                    else
                    {
                        sw.WriteLine("line: (point) {0}", xyS(line.P1.X, line.P1.Y));
                    }
                }
            }
            OCVGridData gridData = new OCVGridData(lines);

            using (StreamWriter sw = new StreamWriter("lines.dmp"))
            {
                sw.WriteLine("------------------------------------------------");
                sw.WriteLine("griddata (HorizontalLines): ");
                foreach (OCVLineData line in gridData.HorizontalLines)
                {
                    sw.WriteLine("line: Y = {0}, X1 = {1} X2 = {2} len = {3}", line.GetY(), line.GetMinValue(), line.GetMaxValue(), line.Length);
                }
                sw.WriteLine("------------------------------------------------");
                sw.WriteLine("griddata (Vertical Lines: ");
                foreach (OCVLineData line in gridData.VerticalLines)
                {
                    sw.WriteLine("line: X = {0}, Y1 = {1} Y2 = {2} len = {3}", line.GetX(), line.GetMinValue(), line.GetMaxValue(), line.Length);
                }
                sw.WriteLine("------------------------------------------------");
            }
            OCVGrid grid = new OCVGrid(gridData);

            using (StreamWriter sw = new StreamWriter("grid.dmp"))
            {
                grid.Dump(sw);
            }

            Image <Bgr, Byte> image3 = lineImage.CopyBlank();

            foreach (OCVCombinedLinesData line in grid.HorizontalLines)
            {
                OCVLineData summ = line.GetSummaryLine();
                image3.Draw(summ.Line, new Bgr(Color.Azure), 2);
            }
            foreach (OCVCombinedLinesData line in grid.VerticalLines)
            {
                OCVLineData summ = line.GetSummaryLine();
                if (summ.Length > 35)
                {
                    image3.Draw(summ.Line, new Bgr(Color.LightPink), 2);
                }
            }
            pictureBox2.Image = image3.Bitmap;

            Image <Bgr, Byte> lineImage2 = img1.CopyBlank();
            OCVGridDefinition gridDef    = grid.Analyze();

            listBox1.Items.Add(String.Format("{0} x {1}", gridDef.Rows, gridDef.Cols));
            for (int r = 0; r <= gridDef.Rows; r++)
            {
                lineImage2.Draw(new LineSegment2D(new Point(gridDef.TopLeft.X, gridDef.RowLocation(r)),
                                                  new Point(gridDef.TopLeft.X + gridDef.Width, gridDef.RowLocation(r))),
                                new Bgr(Color.PeachPuff), 2);
            }
            for (int c = 0; c <= gridDef.Cols; c++)
            {
                lineImage2.Draw(new LineSegment2D(new Point(gridDef.ColLocation(c), gridDef.TopLeft.Y),
                                                  new Point(gridDef.ColLocation(c), gridDef.TopLeft.Y + +gridDef.Height)),
                                new Bgr(Color.MediumTurquoise), 2);
            }

            lineImage2.Draw(new Rectangle(gridDef.TopLeft.X, gridDef.TopLeft.Y, gridDef.Width, gridDef.Height), new Bgr(Color.White), 2);

            pictureBox3.Image = lineImage2.Bitmap;
            testingpixels(gridDef);
            CharacterTest(gridDef);
        }
Пример #6
0
 protected override double GetLocation(OCVLineData line)
 {
     return(line.GetX());
 }
Пример #7
0
 private void RemoveLine(OCVLineData line)
 {
     Lines.Remove(line);
     ReCompute();
 }
Пример #8
0
 protected abstract double GetLocation(OCVLineData line);
Пример #9
0
        public OCVGridDefinition Analyze(double threshold)
        {
            double left = OCVConst.REALLYLARGE, top = OCVConst.REALLYLARGE, right = -OCVConst.REALLYLARGE, bottom = -OCVConst.REALLYLARGE;

            // remove lines that are too small
            RemoveSmallLines(threshold);
            // analyze horizontal lines
            int rows = -1;

            foreach (OCVCombinedLinesData linesGroup in HorizontalLines)
            {
                rows++;
                OCVLineData summaryLine = linesGroup.GetSummaryLine();
                if (summaryLine.GetMinValue() < left)
                {
                    left = summaryLine.GetMinValue();
                }
                if (summaryLine.GetMaxValue() > right)
                {
                    right = summaryLine.GetMaxValue();
                }
                if (summaryLine.GetY() > top)
                {
                    top = summaryLine.GetY();
                }
                if (summaryLine.GetY() < bottom)
                {
                    bottom = summaryLine.GetY();
                }
            }

            // analyze vertical lines
            int cols = -1;

            foreach (OCVCombinedLinesData linesGroup in VerticalLines)
            {
                cols++;
                OCVLineData summaryLine = linesGroup.GetSummaryLine();
                if (summaryLine.GetX() < left)
                {
                    left = summaryLine.GetX();
                }
                if (summaryLine.GetX() > right)
                {
                    right = summaryLine.GetX();
                }
                if (summaryLine.GetMinValue() < top)
                {
                    top = summaryLine.GetMinValue();
                }
                if (summaryLine.GetMaxValue() > bottom)
                {
                    bottom = summaryLine.GetMaxValue();
                }
            }
            OCVGridDefinition result = new OCVGridDefinition(new Point((int)left, (int)top),
                                                             new Point((int)right, (int)bottom),
                                                             rows, cols
                                                             );

            return(result);
        }