Finding contours in vector of connected points [closed]
Hi!
I use a class called ConnectedComponents to split a binary image into vectors of connected points (Point2i).
I find it convenient to use these point vectors when sorting out which blob to use. But once I sort out the appropriate object, I need to perform stuff like circularity measurements. Thus the need for contours.
Is there an algorithm for finding the contour in a vector of points?
Would it be less taxing to convert the point vector to a mat, perform canny and then findContours?
EDIT
One way of doing it is:
- Threshold image
- Use a connectedcomponents class to store individual sets of connected pixels as points
- Perform canny on the thresholded image
- Find the edges
- Map contours with the different sets of connected pixels
- Decide what set(s) of connectedcomponents we want
What I would rather do is
- Threshold image
- Use a connectedcomponents class to store individual sets of connected pixels as points
- Decide what set(s) of connected pixels to use
- Find the edges of that single set.
May be you can use this code :(class ImageInfoCV : public Mat)
I don't understand your question. The
cv.:findContours
function will already split a binary image into a vector of a vector of contour points (X-, Y- coordinates).You have to differ between a data set of gray values (or binary values) and a set of X-, Y- coordiantes. The first one you get when you threshold an image e.g. with
cv::Canny
orcv::threshold
. The second one you get withcv::findContour
, which is applied after thresholding. There is also a functioncv::connectedComponents
which will split your image into a new image (with gray values) where every connected area will get an increasing value starting by 1.So when you want to do blob analysis I recommend you to do a threshold and then findContour, after that you can calculate moments with
cv::moments
for example.@matman ConnectedComponents stores the points of all connected pixels in a cluster, which is useful for other stuff I'm doing. I thought it would be nice to be able to find which of those points describes the contour of the blob without having to threshold again in the canny algorithm.
@LBerger It looks like there is a couple of lines missing in your code window. Could you edit your comment please?
I have change the code :
You can use contour to plot all contour of your label image : contour[i] is contour of region with label i and all points are contour[i][0]...contour[i][contour[i].size()-1] You can use example opencv\samples\cpp\contours2.cpp
@LBerger I am currently using opencv-2.4.9 with a custom ConnectedComponents class. Your solution looks like it is using opencv-3. Is that correct?
Sorry I forget it I use OpenCV 3.0 dev
@LBerger I just compiled opencv-3. My application should be simple enough to be able to use opencv-3 without any hidden bugs...