【问题标题】:C# EmguCV - Circle line thickness calculationC# EmguCV - 圆线粗细计算
【发布时间】:2015-05-10 02:21:39
【问题描述】:

我想像下面这样计算圆线粗细:

哪种方法可以帮助我做到这一点?

感谢您的回复大卫。我是emgucv的新手。所以我不知道从哪里开始。我可以使用精明的边缘做下面的图像。但我无法计算距离,因为我不知道我会使用什么代码。我可以使用哪个代码?

private void button1_Click(object sender, EventArgs e)
{
    string strFileName = string.Empty;
    OpenFileDialog ofd = new OpenFileDialog();
    if (ofd.ShowDialog() == DialogResult.OK)
    {
        //Load image
        Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(ofd.FileName);
        //Convert the img1 to grayscale and then filter out the noise
        Image<Gray, Byte> gray1 = img1.Convert<Gray, Byte>().PyrDown().PyrUp();
        //Canny Edge Detector
        Image<Gray, Byte> cannyGray = gray1.Canny(120, 180);
        pictureBox1.Image = cannyGray.ToBitmap();
    }
}

【问题讨论】:

  • 到目前为止你尝试过什么?我会尝试获取 2 个圆形轮廓的边界矩形并计算它们的宽度或高度之间的差异。有很多方法可以做到这一点,但您需要展示一些代码,以便我们可以帮助您解决问题。

标签: c# geometry emgucv


【解决方案1】:

让我进一步指导你。

//load image
            Image<Gray, Byte> loaded_img = new Image<Gray, byte>(Filename);
            Image<Gray, Byte> Thresh_img = loaded_img.CopyBlank();

            //threshold to make it binary if necessaray
             CvInvoke.cvThreshold(loaded_img.Ptr, Thresh_img.Ptr, 0, 255, Emgu.CV.CvEnum.THRESH.CV_THRESH_OTSU | Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY);
            //get contours of circle
             Contour<Point> Circle_cont = Thresh_img.FindContours();
            //get height & width of the bounding rectangle
             int height_Circle_1 = Circle_cont.BoundingRectangle.Height;
             int width_circle_1 = Circle_cont.BoundingRectangle.Width;

             Circle_cont = Circle_cont.HNext;
             int height_Circle_2 = Circle_cont.BoundingRectangle.Height;
             int width_Circle_2 = Circle_cont.BoundingRectangle.Width;

            //get ring thicknes in Px
             double ring_thickness_1 = Math.Abs(height_Circle_1 - height_Circle_2) / 2;
             double ring_thickness_2 = Math.Abs(width_circle_1 - width_Circle_2) / 2;

这应该可以让您以像素为单位获得戒指的厚度。如果您希望它以厘米为单位,则需要使用实际像素长度缩放 Px 值。我将此代码 sn-p 应用于您的示例图像,并为两个厚度值获得了 56 像素。 我希望这会对你有所帮助。

【讨论】:

  • 感谢大卫的帮助。你的解释很有帮助。
猜你喜欢
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 2020-03-27
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多