【问题标题】:Identify fairly simple shapes with EMGU使用 EMGU 识别相当简单的形状
【发布时间】:2017-01-25 18:05:40
【问题描述】:

我正在尝试识别“T”形以及可以反转的“L”形,如下所示。我在 C# 中使用 EMGU。

形状:T

形状:L(常规)

形状:L(反转)

我试图始终如一地检测这些不同的形状,并尝试使用轮廓方法,如the EMGU shape detection tutorial 所示。问题是它没有正确检测到轮廓点,或者偶尔检测到的时候不可靠。

轮廓逻辑输出

这些形状基本相同,但可以旋转或视角略有不同。什么是一致地检测这些不同形状的准确、有效的方法?

谢谢!

【问题讨论】:

    标签: c# opencv image-processing computer-vision emgucv


    【解决方案1】:

    我已经用您给定的图像尝试了我的算法,结果和代码如下。我已经使用阈值和 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());
            }
    
        }
    

    【讨论】:

    • 虽然我很感谢您的回复,但我不明白您为什么要我通过电子邮件与您联系。这不会使网站上可能有类似问题的其他任何人受益。
    • 因为代码很长。无论如何它可以解决您的问题吗??
    • 长度解决方案既不是问题也不是避免发布代码的理由。请编辑您的答案并发布代码。尝试实施后,我将能够判断它是否正确解决了问题,并相应地标记它。
    • 我已经用代码更新了答案。此代码用于“精确轮廓按钮”点击事件..
    • con = threshold_image; threshold_image 是什么?我看到new_image 设置在该行上方,但我没有看到任何关于threshold_image 是什么的声明或信息。
    猜你喜欢
    • 2011-07-29
    • 1970-01-01
    • 2011-04-17
    • 2011-08-06
    • 1970-01-01
    • 2016-12-03
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多