Esempio n. 1
0
        private Line HoughTransformThird(int x0, int y0, int x1, int y1)
        {
            if (MBM == null)
            {
                return(null);
            }
            x0 = Math.Max(x0, 0);
            y0 = Math.Max(y0, 0);
            x1 = Math.Min(x1, _img.Width - 1);
            y1 = Math.Min(y1, _img.Height - 1);
            var acc = new Acc(_img.Width, _img.Height);

            for (var i = x0; i < x1; i++)
            {
                for (var j = y0; j < y1; j++)
                {
                    if (!MBM[j, i])
                    {
                        continue;
                    }
                    acc.Add(i, j);
                }
            }
            return(acc.Max);
        }
Esempio n. 2
0
        private Line HoughTransformThird(Line input, int offset, int loLimit, int hiLimit, int thetaOffset, bool isVertical)
        {
            int rho, x, y, yOffset, start, end, vote;
            Acc acc = new Acc(_img.Width, _img.Height);

            if (offset > 0)
            {
                start = input.Rh;
                end   = start + offset;
            }
            else
            {
                end   = input.Rh;
                start = end + offset;
            }
            double m_rhos = Math.Sqrt(_img.Width * _img.Width + _img.Height * _img.Height);
            float  sina   = Acc.Sins[input.Th];
            float  cosa   = Acc.Coss[input.Th];

            //input.Th = 180 - input.Th;

            if (isVertical)
            {
                for (rho = start; rho < end; rho += 1)
                {
                    for (y = loLimit; y < hiLimit; y += 2)
                    {
                        x = (int)((-y * sina + rho) / cosa);
                        if (x > 0 && x < _img.Width && y > 0 && y < _img.Height)
                        {
                            if (MBM[y, x])
                            {
                                acc.Add(x, y, input.Th - thetaOffset, input.Th + thetaOffset);
                            }
                            //accumulator.Add(y, x, input.Th - thetaOffset, input.Th + thetaOffset);
                        }
                    }
                }
            }
            else
            {
                for (rho = start; rho < end; rho += 1)
                {
                    for (x = loLimit; x < hiLimit; x += 2)
                    {
                        y = (int)((-x * cosa + rho) / sina);
                        if (x > 0 && x < _img.Width && y > 0 && y < _img.Height)
                        {
                            if (MBM[y, x])
                            {
                                acc.Add(x, y, input.Th - thetaOffset, input.Th + thetaOffset);
                                //accumulator.Add(x, y, inputLine.theta - thetaOffset, inputLine.theta + thetaOffset);
                            }
                        }
                    }
                }
            }
            return(acc.Max);
        }
Esempio n. 3
0
        private bool HoughTransformThird()
        {
            if (MBM == null)
            {
                return(false);
            }
            var acc = new Acc(_img.Width, _img.Height);

            for (var i = _img.Width / 3; i < 2 * (_img.Width / 3); i++)
            {
                for (var j = _img.Height / 3; j < 2 * (_img.Height / 3); j++)
                {
                    if (!MBM[j, i])
                    {
                        continue;
                    }
                    acc.Add(i, j);
                }
            }
            RotateAngle = acc.RotateTheta;
            MaxLine     = acc.Max;
            Hough       = true;
            return(true);
        }