Connected Component Labeling in C++

倾然丶 夕夏残阳落幕 提交于 2019-11-30 17:53:21

问题


I need to use the connected component labeling algorithm on an image in a C++ application. I can implement that myself, but I was trying to use Boost's union-find/disjoint sets implementation since it was mentioned in the union-find wiki article.

I can't figure out how to create the disjoint_sets object so that it'll work with the image data I have (unsigned shorts). What am I missing? The examples in the Boost documentation aren't making any sense to me. Do I need all the extra Graph mumbo-jumbo in those examples when I have an image? OR, is there already an OpenCV connected component labeling implementation. Currently we're using OpenCV 1.1pre1 and Boost 1.37.


回答1:


Surprisingly, there is no CCL in OpenCV. However, there is a workaround that is described in the reference manual. See the example for cvDrawContours. When I tried to use it, I had some strange behaviour on first and last rows and columns of an image, but I probably did something wrong.

An alternative way is to use cvBlobs library.




回答2:


We ended up writing the algorithms for CCL and Union-Find ourselves using the descriptions found on Wikipedia and elsewhere. It seemed easier and faster than adding another library to our application just for this purpose.




回答3:


Another possibility is to use the source codes provided provided by Ali Rahimi, and you can have a look at this.




回答4:


I was able to use disjoint_sets of the boost library for the connected component labeling. But to test, I was trying to create an image with pixel intensities having the value same as its label. This led to the problem which I haven't been able to handle yet. Have a look at the thread.



来源:https://stackoverflow.com/questions/2158901/connected-component-labeling-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!