findContours
을 사용하면 opencv manual 및 Tutorial to find connected components을 참조 할 수 있습니다.
편집 : 코드 튜토리얼에서
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
IplImage *img, *cc_color; /*IplImage is an image in OpenCV*/
CvMemStorage *mem;
CvSeq *contours, *ptr;
img = cvLoadImage(argv[1], 0); /* loads the image from the command line */
cc_color = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);
cvThreshold(img, img, 150, 255, CV_THRESH_BINARY);
mem = cvCreateMemStorage(0);
cvFindContours(img, mem, &contours, sizeof(CvContour), CV_RETR_CCOMP,
CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
CvScalar color = CV_RGB(rand()&255, rand()&255, rand()&255);
cvDrawContours(cc_color, ptr, color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
}
cvSaveImage("result.png", cc_color);
cvReleaseImage(&img);
cvReleaseImage(&cc_color);
return 0;
}
잘 작동합니다. Jason. 나는 당신의 패치를 통합했고, 잘 작동하는 것 같다. 속도도 좋습니다. 어쩌면 일부 속성을 추가하는 기능이 너무 좋을 것입니다 (예 : 영역, centroïd 등). 어쨌든 위대한 일에 감사드립니다. OpenCV 팀이 곧 귀하의 패치를 통합하기를 바랍니다. 이것은 OpenCV IMHO의 심각한 부족입니다. 특히 다른 도서관이 오래되어 IplImage * 만 사용하기 때문에 ... –
+1. 잘 했어. OpenCV에 패치를 통합하는 방법은 무엇입니까? – Alexey
이제 API에 있나요? 그렇다면 문서에 대한 링크가 향후 독자에게 도움이 될 것입니다. – dashesy