本文整理汇总了C#中OpenCvSharp.Mat.Line方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Line方法的具体用法?C# Mat.Line怎么用?C# Mat.Line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.Mat
的用法示例。
在下文中一共展示了Mat.Line方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleCpp
/// <summary>
/// sample of new C++ style wrapper
/// </summary>
private void SampleCpp()
{
// (1) Load the image
using (Mat imgGray = new Mat(FilePath.Image.Goryokaku, ImreadModes.GrayScale))
using (Mat imgStd = new Mat(FilePath.Image.Goryokaku, ImreadModes.Color))
using (Mat imgProb = imgStd.Clone())
{
// Preprocess
Cv2.Canny(imgGray, imgGray, 50, 200, 3, false);
// (3) Run Standard Hough Transform
LineSegmentPolar[] segStd = Cv2.HoughLines(imgGray, 1, Math.PI / 180, 50, 0, 0);
int limit = Math.Min(segStd.Length, 10);
for (int i = 0; i < limit; i++ )
{
// Draws result lines
float rho = segStd[i].Rho;
float theta = segStd[i].Theta;
double a = Math.Cos(theta);
double b = Math.Sin(theta);
double x0 = a * rho;
double y0 = b * rho;
Point pt1 = new Point { X = (int)Math.Round(x0 + 1000 * (-b)), Y = (int)Math.Round(y0 + 1000 * (a)) };
Point pt2 = new Point { X = (int)Math.Round(x0 - 1000 * (-b)), Y = (int)Math.Round(y0 - 1000 * (a)) };
imgStd.Line(pt1, pt2, Scalar.Red, 3, LineTypes.AntiAlias, 0);
}
// (4) Run Probabilistic Hough Transform
LineSegmentPoint[] segProb = Cv2.HoughLinesP(imgGray, 1, Math.PI / 180, 50, 50, 10);
foreach (LineSegmentPoint s in segProb)
{
imgProb.Line(s.P1, s.P2, Scalar.Red, 3, LineTypes.AntiAlias, 0);
}
// (5) Show results
using (new Window("Hough_line_standard", WindowMode.AutoSize, imgStd))
using (new Window("Hough_line_probabilistic", WindowMode.AutoSize, imgProb))
{
Window.WaitKey(0);
}
}
}