私はemgucvを使って基本的な幾何学的形状を特定するプロジェクトを行っています。私は五角形を識別するために次のコードを使用しています。しかし私がそれを実行すると、五角形と円も表示されます。私は五角形だけを出力したい。私は既に円、長方形、三角形を特定しています。このコードを使って五角形だけを表示する方法は?
ありがとうございます!あなたが見つかった輪郭(ギザギザ)エイリアスされ、任意の多角形近似(「スムージング」)は、あまりにも多くの輪郭を変更することができるので、形状を検出するために、輪郭のセグメントの数に依存しないでくださいEmguCvでペンタゴンと六角形を検出する方法
public Image<Bgr, Byte> My_Image;
public Image<Gray, Byte> grayImage;
public Image<Gray, Byte> cannyEdges;
grayImage = My_Image.Convert<Gray, byte>();
public void CannyEdgeDetection()
{
try
{
double cannyThresholdLinking = 120.0;
cannyEdges = grayImage.Canny(cannyThreshold, cannyThresholdLinking);
lines = cannyEdges.HoughLinesBinary(
1, //Distance resolution in pixel-related units
Math.PI/45.0, //Angle resolution measured in radians.
20, //threshold
10, //min Line width
10 //gap between lines
)[0]; //Get the lines from the first channel
}
catch (Exception ex)
{
throw ex;
}
}
public void DetectPentagons()
{
try
{
CannyEdgeDetection();
using (MemStorage storage = new MemStorage())
for (
Contour<Point> contours = cannyEdges.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
storage);
contours != null;
contours = contours.HNext)
{
Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
if (currentContour.Area > 100)
{
if (currentContour.Total == 5)
{
grayImage.Draw(contours, new Bgr(Color.Red), 10);
pictureBox2.Image = obj.grayImage.Bitmap;
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
サイドノート: 'catch(Exception ex) { throw ex; } 'は、スタックトレースを消去するため、役に立たないよりも悪いです。意味的に例外を処理しない場合は、try/catchブロックを完全に削除するだけです。ブレークポイントを設定したりログに記録したりする場合は、 'throw ex'ではなく' throw; 'を呼び出すだけで、スタックトレースはそのまま残ります。 – Blorgbeard
それを得ました。他の図形の代わりにこのコードを使って五角形だけを表示する方法を知っていますか? – RuwanH