形态骨架opencv [英] Morphological skeleton opencv

查看:228
本文介绍了形态骨架opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到一个角色的骨架图像,我已经尝试过OpenCV.But它运行一个永无止境的循环。请帮助我。这是我的代码。谢谢。



I want to get the skeleton image of a character and I have tried that from OpenCV.But it runs a never ending loop.Please help me with this.Here is my code.Thanks.

bool done;
IplConvKernel* element = cvCreateStructuringElementEx( 3, 3,0, 0, CV_SHAPE_CROSS, NULL );
do
{
    cvErode(gray,erode,element,1);
    cvDilate(erode,temp,element,1);
    cvAbsDiff(gray,temp,temp);
    cvOr(skel,temp,skel,NULL);
    cvCopy(erode, gray, NULL);

done = (cvCountNonZero(gray) == 0);
} while (!done);

推荐答案

来自输入图像的名称灰色我认为它是灰度图像。请注意,灰度图像上的侵蚀会传递另一个灰度图像,其中锚像素是结构元素覆盖的所有源像素的最小。这个最小值不一定是零。在迭代地应用侵蚀操作之后,您将得到具有源图像的最小灰度级的图像。因此,对非零的测试不会起作用。



在进行骨架化之前要么进行二值化,要么使用不同的测试来停止迭代。
From the name "gray" of your input image I assume that it is a gray scale image. Notice that an erode on a gray scale image delivers another gray scale image in which the anchor pixel is the minimum of all source pixels as overlayed by the structuring element. This minimum is not necessarily zero. After iteratively applying the erode operation you will end up with an image that has the minimum gray-level of your source image. Hence, the test on non-zero won''t work.

Either binarize before doing the skeletonization or use a different test for stopping your iteration.


这篇关于形态骨架opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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