本文介绍了如何在EmguCv中使用OpenCv 3.0 CvInvoke.HoughLines方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中用EmguCv调用CvInvoke.HoughLines?因此不是HoughLinesP方法。我遇到的麻烦是用于第二个参数的类型,它是IOutputArray。
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.
推荐答案
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();
}
这篇关于如何在EmguCv中使用OpenCv 3.0 CvInvoke.HoughLines方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!