c++ - How to detect all the connected neighboring pixels which have same color value in opencv -
c++ - How to detect all the connected neighboring pixels which have same color value in opencv -
i should able input pixel position , same coloured(in case should black) pixels connected it. how in opencv c++. output pixels should connected each other color black. findcontours() method not work cannot feeded pixel.
opencv has no such function, have implement yourself. easy way implement search algorithm bfs or dfs in trees.
som pseudo-code:
list<pixels> pixels_in_component; stack<pixels> neighbours; neighbours.add(starting_point) while not neightbours.empty: p = neighbours.pop(); pixels_in_component.append(p) each adjacent pixel n of p: if color(n) == color(starting_point): neighbours.append(n)
if utilize stack or queue not relevant , pixels_in_component later contain connected pixels.
or (if restricted black components) can utilize cv::threshold invert image. utilize inverted binary threshold pixels above value mapped zero, while pixels below threshold mapped given value.
if have cv_8uc1 image, phone call threshold( input,output, 1,255, thresh_binary_inv);
to map black pixels 255 , rest zero. can run normal findcontours.
c++ opencv image-processing connected-components
Comments
Post a Comment