あなたの画像で私のアルゴリズムを試したところ、結果とコードは以下の通りです。私はthresholdingとfindcontours関数を使用してあなたの姿を検出しました。
後に正確な輪郭を見つけるためのコードです。輪郭が見つかると、その長さを計算するか、単にそのサイズを保存することができます。同じ輪郭は、どんな方向であっても常に同じサイズまたは長さ(およそ)を持ちます。
Mat original_image = new Mat();
Mat gray = new Mat();
Mat threshold_image = new Mat();
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
Mat new_image = new Mat();
Mat con = new Mat();
//TrackBar Scroll
private void trackBarLow_Scroll(object sender, EventArgs e)
{
try
{
low = trackBarLow.Value;
threshold_value = trackBarThreshold.Value;
CvInvoke.CvtColor(original_image, gray, ColorConversion.Bgr2Gray, 0);
CvInvoke.Threshold(gray, threshold_image, low, threshold_value, ThresholdType.Binary);
Image<Bgr, Byte> threshold_I = threshold_image.ToImage<Bgr, Byte>();
pictureBox2.Image = threshold_I.ToBitmap();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void buttonExactContours_Click(object sender, EventArgs e)
{
try
{
new_image = new Mat(new System.Drawing.Size(640, 480), DepthType.Cv16S, 3);
new_image.SetTo(new Emgu.CV.Structure.MCvScalar(150, 0, 150));
con = threshold_image;
Image<Bgr, Byte> new_image1_I = new_image.ToImage<Bgr, Byte>();
pictureBox3.Image = new_image1_I.ToBitmap();
CvInvoke.FindContours(con, contours, null, RetrType.Ccomp, ChainApproxMethod.ChainApproxSimple, new Point(0, 0));
IInputArrayOfArrays arr;
for (int j = 0; j < contours.Size; j++)
{
arr = contours[j];
//textBox1.AppendText(Environment.NewLine + CvInvoke.ArcLength(arr, true).ToString() + Environment.NewLine);
textBox1.AppendText(Environment.NewLine + contours[j].Size.ToString() + Environment.NewLine);
if (contours[j].Size < 500) //Value "500" may vary according to the size you may want to filter
continue;
}
Image<Bgr, Byte> new_image_I = new_image.ToImage<Bgr, Byte>();
pictureBox2.Image = new_image_I.ToBitmap();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
私は応答に感謝しますが、私は電子メールであなたに連絡するように頼んでいる理由は理解できません。それは、同様の質問をしている可能性のある他の誰にも利益がありません。 – Chad
コードが長いためです。とにかくそれはあなたの問題を解決するのですか? –
長さの問題は、コードの投稿を避けるための問題でも、理由もありません。あなたの答えを編集し、コードを投稿してください。それを実装しようとした後、私はそれが正しく質問を解決するかどうかを判断することができ、それに応じてそれをマークします。 – Chad