使用EmguCV进行骨骼化 [英] Skeletonization using EmguCV

查看:1117
本文介绍了使用EmguCV进行骨骼化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用EmguCV在C#中进行骷髅化。我使用的样本在这个页面的底部是在C + +,我试过,它的工作原理:
http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/

I am trying to make a Skeletonization in C# using EmguCV. I am using the sample at the bottom of this page which is in C++ and I tried that and it works: http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/

我有将鳕鱼转换为C#如下:

I have converted the cod to C# as follows:

        Image<Gray, Byte> eroded = new Image<Gray, byte>(img2.Size);
        Image<Gray, Byte> temp = new Image<Gray, byte>(img2.Size);
        Image<Gray, Byte> skel = new Image<Gray, byte>(img2.Size);
        skel.SetValue(0);
        CvInvoke.cvThreshold(img2, img2, 127, 256, 0);
        StructuringElementEx element = new StructuringElementEx(3, 3, 1, 1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
        bool done = false;

        while (!done)
        {
            CvInvoke.cvErode(img2, eroded, element,1);
            CvInvoke.cvDilate(eroded, temp, element,1);
            temp = img2.Sub(temp);
            skel = skel | temp;
            img2 = eroded;
            if (CvInvoke.cvCountNonZero(img2) == 0) done = true;
        }

但这不行!哪里不对?
在while循环开始时,它会破坏图像img2并将其保存到eroded,然后扩大eroded,然后将其保存到temp。在上面的C#代码,这导致'temp = img2'这是有道理的。那么为什么这是工作在C ++代码而不是n C#?

But this does not work! What is wrong? In the beginning of the while loop, it erodes the image 'img2' and saves it to 'eroded', then it dilates 'eroded' and then saves it to 'temp'. In the above C# code, this results in 'temp=img2' which makes sense. So why this is working in the C++ code and not n C#? Is something wrong with the way 'element' is defined in the above C# code?

提前感谢!

推荐答案

您的代码与图片一样正常,如下所示: http:/ /i.stack.imgur.com/YMA4r.jpg

Your code works fine with image like this: http://i.stack.imgur.com/YMA4r.jpg

我想你使用图片,白色背景,而不是黑色。

I think you use image, with white backround instead of black.

要克服的简单方法是反转图片。

Easy way to overcome is to invert your image.

Image<Gray, Byte> invert_img = (new Image<Gray, byte>(img_old.Width, img_old.Height, new Gray(255))).Sub(img_old);

然后您可以将其反转。

skel = (new Image<Gray, byte>(img_old.Width, img_old.Height, new Gray(255))).Sub(skel);

这篇关于使用EmguCV进行骨骼化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆