/code/FullApp/OpenCV/lib/iPhoneOS/share/opencv/samples/c/pyramid_segmentation.c

https://github.com/siegleal/iSanta · C · 102 lines · 63 code · 22 blank · 17 comment · 3 complexity · c09d2b1c518a3d894262cc26962f22d1 MD5 · raw file

  1. #ifdef _CH_
  2. #pragma package <opencv>
  3. #endif
  4. #define CV_NO_BACKWARD_COMPATIBILITY
  5. #ifndef _EiC
  6. #include "cv.h"
  7. #include "highgui.h"
  8. #include <math.h>
  9. #endif
  10. IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
  11. CvSize size;
  12. int w0, h0,i;
  13. int threshold1, threshold2;
  14. int l,level = 4;
  15. int sthreshold1, sthreshold2;
  16. int l_comp;
  17. int block_size = 1000;
  18. float parameter;
  19. double threshold;
  20. double rezult, min_rezult;
  21. CvFilter filter = CV_GAUSSIAN_5x5;
  22. CvConnectedComp *cur_comp, min_comp;
  23. CvSeq *comp;
  24. CvMemStorage *storage;
  25. CvPoint pt1, pt2;
  26. void ON_SEGMENT(int a)
  27. {
  28. cvPyrSegmentation(image0, image1, storage, &comp,
  29. level, threshold1+1, threshold2+1);
  30. /*l_comp = comp->total;
  31. i = 0;
  32. min_comp.value = cvScalarAll(0);
  33. while(i<l_comp)
  34. {
  35. cur_comp = (CvConnectedComp*)cvGetSeqElem ( comp, i );
  36. if(fabs(255- min_comp.value.val[0])>
  37. fabs(255- cur_comp->value.val[0]) &&
  38. fabs(min_comp.value.val[1])>
  39. fabs(cur_comp->value.val[1]) &&
  40. fabs(min_comp.value.val[2])>
  41. fabs(cur_comp->value.val[2]) )
  42. min_comp = *cur_comp;
  43. i++;
  44. }*/
  45. cvShowImage("Segmentation", image1);
  46. }
  47. int main( int argc, char** argv )
  48. {
  49. char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
  50. if( (image[0] = cvLoadImage( filename, 1)) == 0 )
  51. return -1;
  52. cvNamedWindow("Source", 0);
  53. cvShowImage("Source", image[0]);
  54. cvNamedWindow("Segmentation", 0);
  55. storage = cvCreateMemStorage ( block_size );
  56. image[0]->width &= -(1<<level);
  57. image[0]->height &= -(1<<level);
  58. image0 = cvCloneImage( image[0] );
  59. image1 = cvCloneImage( image[0] );
  60. // segmentation of the color image
  61. l = 1;
  62. threshold1 =255;
  63. threshold2 =30;
  64. ON_SEGMENT(1);
  65. sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
  66. sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
  67. cvShowImage("Segmentation", image1);
  68. cvWaitKey(0);
  69. cvDestroyWindow("Segmentation");
  70. cvDestroyWindow("Source");
  71. cvReleaseMemStorage(&storage );
  72. cvReleaseImage(&image[0]);
  73. cvReleaseImage(&image0);
  74. cvReleaseImage(&image1);
  75. return 0;
  76. }
  77. #ifdef _EiC
  78. main(1,"pyramid_segmentation.c");
  79. #endif