X-Git-Url: http://git.maemo.org/git/?p=opencv;a=blobdiff_plain;f=apps%2FHawk%2Fdemos%2FDemConvex.c;fp=apps%2FHawk%2Fdemos%2FDemConvex.c;h=0000000000000000000000000000000000000000;hp=b76597513336f5bc54a947b978bbd945381e33b9;hb=e4c14cdbdf2fe805e79cd96ded236f57e7b89060;hpb=454138ff8a20f6edb9b65a910101403d8b520643 diff --git a/apps/Hawk/demos/DemConvex.c b/apps/Hawk/demos/DemConvex.c deleted file mode 100644 index b765975..0000000 --- a/apps/Hawk/demos/DemConvex.c +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************** -* -* -* This program is demonstration for functions: cvConvexHull() and -* cvConvexityDefects. Program finds contours, convex hull -* and defects of convexity of this contours. -* -* Trackbar specify threshold parametr. -* -* White lines is contours. Blue lines is convex hull. -* Red triangles marks defects of convexity. -* -* -* Autor: Denis Burenkov. -* -* -* -********************************************************************************/ - -char file_name[] = "image009.bmp"; - -char wndname01[] = "Source image"; -char wndname02[] = "Output image"; -char barname01[] = "Threshold factor"; -int slider_pos[1] = {70}; - - -// Load the source image. HighGUI use. -IPLIMAGE image01 = load_iplimage( file_name ); - -if(image01==NULL) -{ - printf("File '%s' not found.\n", file_name); - -} - -// Create the destination images. HighGUI use. -IPLIMAGE image02 = cvCreateImage(cvSize(image01->width, image01->height), - image01->depth, - 1); - -IPLIMAGE image03 = cvCreateImage(cvSize(image01->width, image01->height), - image01->depth, - 1); - -IPLIMAGE image04 = cvCreateImage(cvSize(image01->width, image01->height), - image01->depth, - 3); - -// Make onechannel image. IPL use. -iplColorToGray(image01,image03); - - -// Create windows. HighGUI use. -named_window(wndname01, 0); -named_window(wndname02, 0); - -// Show the image. HighGUI use. -show_iplimage(wndname01, image03); - - - - -// Define trackbar callback functon. This function find contours, convex hull -// and defects of convexity. Then draw it all. -void func(int h) -{ - CvMemStorage* stor; - CvMemStorage* stor02; - CvMemStorage* stor03; - CvSeq* cont; - CvSeq* seqhull; - CvSeq* defects; - int* hull; - int hullsize; - CvPoint* PointArray; - CvConvexityDefect* defectArray; - - - // Create memory storage for sequence. - stor = cvCreateMemStorage(0); - stor02 = cvCreateMemStorage(0); - stor03 = cvCreateMemStorage(0); - - // Threshold the source image. This needful for cvFindContours(). - cvThreshold( image03, image02, slider_pos[0], 255, CV_THRESH_BINARY ); - - // Find all contours. - cvFindContours( image02, stor, &cont, sizeof(CvContour), - CV_RETR_LIST, CV_CHAIN_APPROX_NONE); - - // Clear image - cvSetZero(image04); - - // This cycle draw all contours and find convex hull - // and defects of convexity. - for(;cont;cont = cont->h_next) - { - int i; // Indicator of cycles. - int count = cont->total; // This is number point in contour - CvPoint center; - CvSize size; - - - // Alloc memory for contour point set. - PointArray = malloc( count*sizeof(CvPoint) ); - - // Alloc memory for indices of convex hull vertices. - hull = malloc(sizeof(int)*count); - - // Get contour point set. - cvCvtSeqToArray(cont, PointArray, CV_WHOLE_SEQ); - - - // Find convex hull for curent contour. - cvConvexHull( PointArray, - count, - NULL, - CV_COUNTER_CLOCKWISE, - hull, - &hullsize); - - // Find convex hull for current contour. - // This required for cvConvexityDefects(). - seqhull = cvContourConvexHull( cont, - CV_COUNTER_CLOCKWISE, - stor02); - - // This required for cvConvexityDefects(). - // Otherwise cvConvexityDefects() falled. - if( hullsize < 4 ) - continue; - - // Find defects of convexity of current contours. - defects = cvConvexityDefects( cont, - seqhull, - stor03); - - // This cycle marks all defects of convexity of current contours. - for(;defects;defects = defects->h_next) - { - int nomdef = defects->total; // defect amount - - if(nomdef == 0) - continue; - - // Alloc memory for defect set. - defectArray = malloc(sizeof(CvConvexityDefect)*nomdef); - - // Get defect set. - cvCvtSeqToArray(defects,defectArray, CV_WHOLE_SEQ); - - // Draw marks for all defects. - for(i=0; i