How to use OpenCv 3.0 CvInvoke.HoughLines method with EmguCv

倖福魔咒の 提交于 2020-01-06 02:39:16

问题


How to call CvInvoke.HoughLines with EmguCv in C#? Thus not the HoughLinesP method. The trouble I am experiencing is the type to use for the second parameter, which is of IOutputArray.


回答1:


        LineSegment2D[] lines;
        using (var vector = new VectorOfPointF())
        {
            CvInvoke.HoughLines(cannyEdges, vector,
                _arguments.HoughLineArgs.DistanceResolution,
                Math.PI / _arguments.HoughLineArgs.AngleResolution,
                _arguments.HoughLineArgs.Threshold);

            var linesList = new List<LineSegment2D>();
            for (var i = 0; i < vector.Size; i++)
            {
                var rho = vector[i].X;
                var theta = vector[i].Y;
                var pt1 = new Point();
                var pt2 = new Point();
                var a = Math.Cos(theta);
                var b = Math.Sin(theta);
                var x0 = a * rho;
                var y0 = b * rho;
                pt1.X = (int)Math.Round(x0 + mat.Width * (-b));
                pt1.Y = (int)Math.Round(y0 + mat.Height * (a));
                pt2.X = (int)Math.Round(x0 - mat.Width * (-b));
                pt2.Y = (int)Math.Round(y0 - mat.Height * (a));

                linesList.Add(new LineSegment2D(pt1, pt2));
            }

            lines = linesList.ToArray();
        }


来源:https://stackoverflow.com/questions/38031836/how-to-use-opencv-3-0-cvinvoke-houghlines-method-with-emgucv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!