Exemplo n.º 1
0
        public override bool run()
        {
            try
            {
                method    = (Method)getValue("method");
                rho       = (double)getValue("rho");
                theta     = (double)getValue("theta");
                threshold = (int)getValue("threshold");
                switch (method)
                {
                case Method.SHT:
                    LineSegmentPolar[] polars = src.HoughLines(rho, theta, threshold, 0, 0);
                    result = new LineSegmentPoint[polars.Length];
                    for (int i = 0; i < polars.Length; i++)
                    {
                        LineSegmentPolar p = polars[i];
                        result[i] = p.ToSegmentPoint(src.Width);
                    }
                    break;

                case Method.MHT:
                    srn = (double)getValue("srn");
                    stn = (double)getValue("stn");
                    LineSegmentPolar[] m_polars = src.HoughLines(rho, theta, threshold, srn, stn);
                    result = new LineSegmentPoint[m_polars.Length];
                    for (int i = 0; i < m_polars.Length; i++)
                    {
                        LineSegmentPolar p = m_polars[i];
                        result[i] = p.ToSegmentPoint(1.0);
                    }
                    break;

                case Method.PPHT:
                    minLineLength = (double)getValue("minLineLength");
                    maxLineGap    = (double)getValue("maxLineGap");
                    result        = src.HoughLinesP(rho, theta, threshold, minLineLength, maxLineGap);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Exemplo n.º 2
0
        public static void Draw(this LineSegmentPolar line, Mat image, Scalar color)
        {
            var xz = line.XPosOfLine(0);
            var yz = line.YPosOfLine(0);

            if (xz.HasValue && !yz.HasValue)
            {
                image.Line(new Point(xz.Value, 0), new Point(xz.Value, image.Height), color);
            }
            else if (!xz.HasValue && yz.HasValue)
            {
                image.Line(new Point(0, yz.Value), new Point(image.Width, yz.Value), color);
            }
            else
            {
                var seg = line.ToSegmentPointX(0, image.Width);
                image.Line(seg.P1, seg.P2, color);
            }
        }
Exemplo n.º 3
0
 public static bool IsBetween(this LineSegmentPolar line, double first, double second)
 {
     return(line.Theta >= first / 180 * Math.PI && line.Theta <= second / 180 * Math.PI);
 }
Exemplo n.º 4
0
 public static bool IsSimilarTo(this LineSegmentPolar line, LineSegmentPolar thatLine)
 {
     return(Math.Abs(line.Rho - thatLine.Rho) < 10 && Math.Abs(line.Theta - thatLine.Theta) < 0.1);
 }