本文整理汇总了C#中OpenCvSharp.IplImage.HoughCircles方法的典型用法代码示例。如果您正苦于以下问题:C# IplImage.HoughCircles方法的具体用法?C# IplImage.HoughCircles怎么用?C# IplImage.HoughCircles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.IplImage
的用法示例。
在下文中一共展示了IplImage.HoughCircles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HoughCircles
public HoughCircles()
{
using (IplImage imgSrc = new IplImage(Const.ImageWalkman, LoadMode.Color))
using (IplImage imgGray = new IplImage(imgSrc.Size, BitDepth.U8, 1))
using (IplImage imgHough = imgSrc.Clone())
{
Cv.CvtColor(imgSrc, imgGray, ColorConversion.BgrToGray);
Cv.Smooth(imgGray, imgGray, SmoothType.Gaussian, 9);
//Cv.Canny(imgGray, imgGray, 75, 150, ApertureSize.Size3);
using (CvMemStorage storage = new CvMemStorage())
{
CvSeq<CvCircleSegment> seq = imgGray.HoughCircles(storage, HoughCirclesMethod.Gradient, 1, 100, 150, 55, 0, 0);
foreach (CvCircleSegment item in seq)
{
imgHough.Circle(item.Center, (int)item.Radius, CvColor.Red, 3);
}
}
// (5)検出結果表示用のウィンドウを確保し表示する
using (new CvWindow("gray", WindowMode.AutoSize, imgGray))
using (new CvWindow("Hough circles", WindowMode.AutoSize, imgHough))
{
CvWindow.WaitKey(0);
}
}
}
示例2: timer1_Tick
private void timer1_Tick(object sender, EventArgs e)
{
// キャプチャの開始. Capture starts.
IplImage ipl1 = capture.QueryFrame();
IplImage ipl2 = new IplImage(ipl1.Size, BitDepth.U8, 1);
IplImage ipl3 = ipl1.Clone();
//IplImage ipl2 = capture.QueryFrame();
//Cv.CvtColor(ipl1, ipl1, ColorConversion.BgrToHsv);
//Mat mat = new Mat(ipl1, true);
// 取得したカメラ画像の高さと幅を取得し、labelに表示. Height and width of camera are shown in label.
labelWidth.Text = capture.FrameWidth.ToString();
labelHeight.Text = capture.FrameHeight.ToString();
if (ipl1 != null)
{
// pictureBoxに取得した画像を表示. Show the captured image.
pictureBox1.Image = ipl1.ToBitmap();
// メモリリークが発生するらしいので
// プログラムが動的に確保したメモリ領域のうち、
// 不要になった領域を定期的に自動解放する
if (GC.GetTotalMemory(false) > 600000)
{
GC.Collect();
}
/*
// Image processing should be written from here.
// Extract red color
for (int y = 0; y < ipl1.Height; y++)
{
for (int x = 0; x < ipl1.Width; x++)
{
CvColor c = ipl1[y, x];
// Red color extraction
// If the pixel is red-like, the image is white, else black.
if (c.R > 80 && c.B < 70 && c.G < 70)
{
ipl1[y, x] = new CvColor()
{
B = 255,
G = 255,
R = 255,
};
}
else
{
ipl1[y, x] = new CvColor()
{
// Red color extraction
B = 0,
G = 0,
R = 0,
};
}
}
}
*/
// 追加した記述
Cv.CvtColor(ipl1, ipl2, ColorConversion.BgrToGray);
Cv.Smooth(ipl2, ipl2, SmoothType.Gaussian, 9);
using (CvMemStorage storage = new CvMemStorage())
{
CvSeq<CvCircleSegment> seq = ipl2.HoughCircles(storage, HoughCirclesMethod.Gradient, 1, 100, 150, 55, 0, 0);
foreach (CvCircleSegment item in seq)
{
ipl3.Circle(item.Center, (int)item.Radius, CvColor.Red, 3);
ipl3.Circle(item.Center, 1, CvColor.Red, 3);
labelCenter.Text = item.Center.ToString();
}
}
//Cv.Laplace(ipl1, ipl2, ApertureSize.Size3);
// Show the image to picturebox2.
pictureBox2.Image = ipl2.ToBitmap();
pictureBox3.Image = ipl3.ToBitmap();
}
else
{
timer1.Stop();
}
}