use cvPrySegmentation

//use cvPrySegmentation
void f(
   IplImage *src,
   IplImage *dst
   ) {
	   CvMemStorage *storage = cvCreateMemStorage(0);
	   CvSeq *comp = NULL;
	   cvPyrSegmentation(
		   src,
		   dst,
		   storage,
		   &comp,
		   4,
		   200,
		   50
		   );
	   int n_comp = comp ->total;
	   for(int i = 0; i < n_comp; ++i) {
		   CvConnectedComp *cc = (CvConnectedComp *)cvGetSeqElem(comp, i);
	   }
	   cvReleaseMemStorage(&storage);
}
int _tmain(int argc, _TCHAR* argv[]) {
	// Create a named window with a the name of the file.
	cvNamedWindow("Test", 1);
	// Load the image from the given file name.
	IplImage* src = cvLoadImage("Lena.jpg");
	if(!src) { 
		perror("Cannot open the file\n");
		return -1;
	}
	IplImage* dst = cvCreateImage(cvGetSize(src), src->depth, src->nChannels);
	f(src, dst);

	// Show the image in the named window
	cvShowImage("Test", dst);

	// Idle until the user hits the "Esc" key.
	while(1) { 
		if( cvWaitKey(100) == 27 ) 
			break; 
	}

	// Clean up
	cvDestroyWindow("Test");
	cvReleaseImage(&src);
	cvReleaseImage(&dst);

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章