Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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);
Posted
Updated 25-Mar-13 19:37pm
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900