是的,您可以使用cvFindContours()
. 它返回指向找到的第一个序列的指针。使用该指针,您可以遍历找到的所有序列。
// your image converted to grayscale
IplImage* grayImg = LoadImage(...);
// image for drawing contours onto
IplImage* colorImg = cvCreateImage(cvGetSize(grayImg), 8, 3);
// memory where cvFindContours() can find memory in which to record the contours
CvMemStorage* memStorage = cvCreateMemStorage(0);
// find the contours on image *grayImg*
CvSeq* contours = 0;
cvFindContours(grayImg, memStorage, &contours);
// traverse through and draw contours
for(CvSeq* c = contours; c != NULL; c = c->h_next)
{
cvCvtColor( grayImg, colorImg, CV_GRAY2BGR );
cvDrawContours(
colorImg,
c,
CVX_RED,
CVX_BLUE,
0, // Try different values of max_level, and see what happens
2,
8
);
}
除了这种方法,我建议你看看cvBlobs
or cvBlobsLib
。后者作为官方 blob 检测库集成在 OpenCV 2.0 中。