本文整理汇总了C#中OpenCvSharp.IplImage.HoughLines2方法的典型用法代码示例。如果您正苦于以下问题:C# IplImage.HoughLines2方法的具体用法?C# IplImage.HoughLines2怎么用?C# IplImage.HoughLines2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.IplImage
的用法示例。
在下文中一共展示了IplImage.HoughLines2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleC
/// <summary>
/// sample of C style wrapper
/// </summary>
private void SampleC()
{
// cvHoughLines2
using (IplImage srcImgGray = new IplImage(FilePath.Image.Goryokaku, LoadMode.GrayScale))
using (IplImage srcImgStd = new IplImage(FilePath.Image.Goryokaku, LoadMode.Color))
using (IplImage srcImgProb = srcImgStd.Clone())
{
Cv.Canny(srcImgGray, srcImgGray, 50, 200, ApertureSize.Size3);
using (CvMemStorage storage = new CvMemStorage())
{
// Standard algorithm
CvSeq lines = srcImgGray.HoughLines2(storage, HoughLinesMethod.Standard, 1, Math.PI / 180, 50, 0, 0);
// wrapper style
//CvLineSegmentPolar[] lines = src_img_gray.HoughLinesStandard(1, Math.PI / 180, 50, 0, 0);
int limit = Math.Min(lines.Total, 10);
for (int i = 0; i < limit; i++)
{
// native code style
/*
unsafe
{
float* line = (float*)lines.GetElem<IntPtr>(i).Value.ToPointer();
float rho = line[0];
float theta = line[1];
}
//*/
// wrapper style
CvLineSegmentPolar elem = lines.GetSeqElem<CvLineSegmentPolar>(i).Value;
float rho = elem.Rho;
float theta = elem.Theta;
double a = Math.Cos(theta);
double b = Math.Sin(theta);
double x0 = a * rho;
double y0 = b * rho;
CvPoint pt1 = new CvPoint { X = Cv.Round(x0 + 1000 * (-b)), Y = Cv.Round(y0 + 1000 * (a)) };
CvPoint pt2 = new CvPoint { X = Cv.Round(x0 - 1000 * (-b)), Y = Cv.Round(y0 - 1000 * (a)) };
srcImgStd.Line(pt1, pt2, CvColor.Red, 3, LineType.AntiAlias, 0);
}
// Probabilistic algorithm
lines = srcImgGray.HoughLines2(storage, HoughLinesMethod.Probabilistic, 1, Math.PI / 180, 50, 50, 10);
// wrapper style
//CvLineSegmentPoint[] lines = src_img_gray.HoughLinesProbabilistic(1, Math.PI / 180, 50, 0, 0);
for (int i = 0; i < lines.Total; i++)
{
// native code style
/*
unsafe
{
CvPoint* point = (CvPoint*)lines.GetElem<IntPtr>(i).Value.ToPointer();
src_img_prob.Line(point[0], point[1], CvColor.Red, 3, LineType.AntiAlias, 0);
}
//*/
// wrapper style
CvLineSegmentPoint elem = lines.GetSeqElem<CvLineSegmentPoint>(i).Value;
srcImgProb.Line(elem.P1, elem.P2, CvColor.Red, 3, LineType.AntiAlias, 0);
}
}
using (new CvWindow("Hough_line_standard", WindowMode.AutoSize, srcImgStd))
using (new CvWindow("Hough_line_probabilistic", WindowMode.AutoSize, srcImgProb))
{
CvWindow.WaitKey(0);
}
}
}
示例2: SampleC
/// <summary>
/// sample of C style wrapper
/// </summary>
private void SampleC()
{
// cvHoughLines2
// 標準的ハフ変換と確率的ハフ変換を指定して線(線分)の検出を行なう.サンプルコード内の各パラメータ値は処理例の画像に対してチューニングされている.
// (1)画像の読み込み
using (IplImage srcImgGray = new IplImage(Const.ImageGoryokaku, LoadMode.GrayScale))
using (IplImage srcImgStd = new IplImage(Const.ImageGoryokaku, LoadMode.Color))
using (IplImage srcImgProb = srcImgStd.Clone())
{
// (2)ハフ変換のための前処理
Cv.Canny(srcImgGray, srcImgGray, 50, 200, ApertureSize.Size3);
using (CvMemStorage storage = new CvMemStorage())
{
// (3)標準的ハフ変換による線の検出と検出した線の描画
CvSeq lines = srcImgGray.HoughLines2(storage, HoughLinesMethod.Standard, 1, Math.PI / 180, 50, 0, 0);
// wrapper style
//CvLineSegmentPolar[] lines = src_img_gray.HoughLinesStandard(1, Math.PI / 180, 50, 0, 0);
int limit = Math.Min(lines.Total, 10);
for (int i = 0; i < limit; i++)
{
// native code style
/*
unsafe
{
float* line = (float*)lines.GetElem<IntPtr>(i).Value.ToPointer();
float rho = line[0];
float theta = line[1];
}
//*/
// wrapper style
CvLineSegmentPolar elem = lines.GetSeqElem<CvLineSegmentPolar>(i).Value;
float rho = elem.Rho;
float theta = elem.Theta;
double a = Math.Cos(theta);
double b = Math.Sin(theta);
double x0 = a * rho;
double y0 = b * rho;
CvPoint pt1 = new CvPoint { X = Cv.Round(x0 + 1000 * (-b)), Y = Cv.Round(y0 + 1000 * (a)) };
CvPoint pt2 = new CvPoint { X = Cv.Round(x0 - 1000 * (-b)), Y = Cv.Round(y0 - 1000 * (a)) };
srcImgStd.Line(pt1, pt2, CvColor.Red, 3, LineType.AntiAlias, 0);
}
// (4)確率的ハフ変換による線分の検出と検出した線分の描画
lines = srcImgGray.HoughLines2(storage, HoughLinesMethod.Probabilistic, 1, Math.PI / 180, 50, 50, 10);
// wrapper style
//CvLineSegmentPoint[] lines = src_img_gray.HoughLinesProbabilistic(1, Math.PI / 180, 50, 0, 0);
for (int i = 0; i < lines.Total; i++)
{
// native code style
/*
unsafe
{
CvPoint* point = (CvPoint*)lines.GetElem<IntPtr>(i).Value.ToPointer();
src_img_prob.Line(point[0], point[1], CvColor.Red, 3, LineType.AntiAlias, 0);
}
//*/
// wrapper style
CvLineSegmentPoint elem = lines.GetSeqElem<CvLineSegmentPoint>(i).Value;
srcImgProb.Line(elem.P1, elem.P2, CvColor.Red, 3, LineType.AntiAlias, 0);
}
}
// (5)検出結果表示用のウィンドウを確保し表示する
using (new CvWindow("Hough_line_standard", WindowMode.AutoSize, srcImgStd))
using (new CvWindow("Hough_line_probabilistic", WindowMode.AutoSize, srcImgProb))
{
CvWindow.WaitKey(0);
}
}
}