1 | initial version |
First, access matrix elements using row and then column, not the other way around. Second, you should take a look at your image. It is not binary. I did a threshold using gimp and around your skeleton lines are lots of pixels with values < 10 which of course get added to the list and are processed. So binarize the image. Plus, I forgot one thing. Change the beginning of the loop to this: Point p=vect1[0]; vect1.erase(vect1.begin()); if (img.at<uchar>(p.y,p.x) == 0) { continue; } img.at<uchar>(p.y,p.x)=0; ... Otherwise, it is possible that a point gets visited again a second time e.g. if you have points that are next to each other.
Plus, since you want to have the different lines from the middle, you have to call the algorithm on the pixel above, below left and below right of your middle point. If you call it once with the middle, it adds everything in the picture into one list.