Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#EmguCV-圆线厚度计算_C#_Geometry_Emgucv - Fatal编程技术网

C#EmguCV-圆线厚度计算

C#EmguCV-圆线厚度计算,c#,geometry,emgucv,C#,Geometry,Emgucv,我想像下面这样圈出线厚度计算: 哪种方法可以帮助我做到这一点 谢谢你的回复,大卫。我是emgucv的新手。所以我不知道从哪里开始。我可以使用canny edge制作以下图像。但是我不能计算距离,因为我不知道我会用什么代码。我可以使用哪种代码 private void button1_Click(object sender, EventArgs e) { string strFileName = string.Empty; OpenFileDialog ofd = new Ope

我想像下面这样圈出线厚度计算:

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

谢谢你的回复,大卫。我是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();
    }
}
private void按钮1\u单击(对象发送者,事件参数e)
{
string strFileName=string.Empty;
OpenFileDialog ofd=新建OpenFileDialog();
if(ofd.ShowDialog()==DialogResult.OK)
{
//加载图像
图像img1=新图像(ofd.FileName);
//将img1转换为灰度,然后滤除噪声
Image gray1=img1.Convert().PyrDown().PyrUp();
//Canny边缘检测器
图像cannyGray=gray1.Canny(120180);
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;
//加载图像
已加载图像\u img=新图像(文件名);
Image Thresh_img=load_img.CopyBlank();
//如果需要,将其设置为二进制的阈值
CvInvoke.cvThreshold(加载的_img.Ptr,Thresh _img.Ptr,0,255,Emgu.CvEnum.Thresh.CV(Thresh)OTSU | Emgu.CV.CvEnum.Thresh.CV(Thresh)二进制文件);
//得到圆的轮廓
轮廓圆_cont=Thresh_img.FindContours();
//获取边框的高度和宽度
int height\u Circle\u 1=Circle\u cont.BoundingRectangle.height;
int width\u circle\u 1=圆\u cont.BoundingRectangle.width;
圆圈_cont=圆圈_cont.HNext;
int height_Circle_2=Circle_cont.BoundingRectangle.height;
int width\u Circle\u 2=圆\u cont.BoundingRectangle.width;
//在Px中获得环的厚度
双环_厚度_1=数学Abs(高度_圆_1-高度_圆_2)/2;
双环_厚度_2=Math.Abs(宽度_圆_1-宽度_圆_2)/2;
这应该可以得到戒指的像素厚度。如果你想以厘米为单位,你需要用真实的像素长度来缩放Px值。我将此代码片段应用于示例图像,两个厚度值均为56像素。
我希望这会对你有所帮助。

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