PageRenderTime 66ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/source/3rd_party/opencv/sources/samples/c/pyramid_segmentation.c

https://gitlab.com/Ruggero/SparkEngine_Desktop
C | 99 lines | 74 code | 24 blank | 1 comment | 3 complexity | 887da71084efdaed4439c63c75915ccd MD5 | raw file
  1. #include "opencv2/imgproc/imgproc.hpp"
  2. #include "opencv2/highgui/highgui.hpp"
  3. #include "opencv2/imgproc/imgproc_c.h"
  4. #include "opencv2/legacy/legacy.hpp"
  5. #include <stdio.h>
  6. static void help(void)
  7. {
  8. printf("\nThis program demonstrated color pyramid segmentation cvcvPyrSegmentation() which is controlled\n"
  9. "by two trhesholds which can be manipulated by a trackbar. It can take an image file name or defaults to 'fruits.jpg'\n"
  10. "Usage :\n"
  11. "./pyaramid_segmentation [image_path_filename -- Defaults to fruits.jpg]\n\n"
  12. );
  13. }
  14. IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
  15. CvSize size;
  16. int w0, h0,i;
  17. int threshold1, threshold2;
  18. int l,level = 4;
  19. int sthreshold1, sthreshold2;
  20. int l_comp;
  21. int block_size = 1000;
  22. float parameter;
  23. double threshold;
  24. double rezult, min_rezult;
  25. int filter = CV_GAUSSIAN_5x5;
  26. CvConnectedComp *cur_comp, min_comp;
  27. CvSeq *comp;
  28. CvMemStorage *storage;
  29. CvPoint pt1, pt2;
  30. static void ON_SEGMENT(int a)
  31. {
  32. (void)a;
  33. cvPyrSegmentation(image0, image1, storage, &comp,
  34. level, threshold1+1, threshold2+1);
  35. cvShowImage("Segmentation", image1);
  36. }
  37. int main( int argc, char** argv )
  38. {
  39. char* filename;
  40. help();
  41. filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
  42. if( (image[0] = cvLoadImage( filename, 1)) == 0 )
  43. {
  44. help();
  45. printf("Cannot load fileimage - %s\n", filename);
  46. return -1;
  47. }
  48. cvNamedWindow("Source", 0);
  49. cvShowImage("Source", image[0]);
  50. cvNamedWindow("Segmentation", 0);
  51. storage = cvCreateMemStorage ( block_size );
  52. image[0]->width &= -(1<<level);
  53. image[0]->height &= -(1<<level);
  54. image0 = cvCloneImage( image[0] );
  55. image1 = cvCloneImage( image[0] );
  56. // segmentation of the color image
  57. l = 1;
  58. threshold1 =255;
  59. threshold2 =30;
  60. ON_SEGMENT(1);
  61. sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255, ON_SEGMENT);
  62. sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255, ON_SEGMENT);
  63. cvShowImage("Segmentation", image1);
  64. cvWaitKey(0);
  65. cvDestroyWindow("Segmentation");
  66. cvDestroyWindow("Source");
  67. cvReleaseMemStorage(&storage );
  68. cvReleaseImage(&image[0]);
  69. cvReleaseImage(&image0);
  70. cvReleaseImage(&image1);
  71. return 0;
  72. }
  73. #ifdef _EiC
  74. main(1,"pyramid_segmentation.c");
  75. #endif