C# EmguCV - 圆线粗细计算

C# EmguCV - Circle line thickness calculation

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

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

感谢大卫的回复。我是 emgucv 的新手。所以我不知道我将从哪里开始。我可以使用 canny edge 做下图。但是我无法计算距离,因为我不知道我会使用什么代码。我可以使用哪些代码?

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();
    }
}

让我进一步指导你。

//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 值。我将此代码片段应用于您的示例图像,并为两个厚度值获得了 56 像素。 希望对您有所帮助。