/src/osuar_ground_station/osuar_vision/include/cvblobs/testBlobs/main.cpp

https://github.com/osuar/iarc · C++ · 103 lines · 59 code · 30 blank · 14 comment · 6 complexity · 1f4b2e1a7d3091c7b1c1f980a6a48a6a MD5 · raw file

  1. // main.cpp : Defines the entry point for the console application.
  2. //
  3. //#include "stdafx.h" //AO
  4. #include "opencv/cv.h"
  5. #include "opencv/highgui.h"
  6. #include <stdio.h>
  7. //#include <conio.h> //AO
  8. // Main blob library include
  9. #include "BlobResult.h"
  10. char wndname[] = "Blob Extraction";
  11. char tbarname1[] = "Threshold";
  12. char tbarname2[] = "Blob Size";
  13. // The output and temporary images
  14. IplImage* originalThr = 0;
  15. IplImage* original = 0;
  16. IplImage* displayedImage = 0;
  17. int param1,param2;
  18. // threshold trackbar callback
  19. void on_trackbar( int dummy )
  20. {
  21. if(!originalThr)
  22. {
  23. originalThr = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,1);
  24. }
  25. if(!displayedImage)
  26. {
  27. displayedImage = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,3);
  28. }
  29. // threshold input image
  30. cvThreshold( original, originalThr, param1, 255, CV_THRESH_BINARY );
  31. // get blobs and filter them using its area
  32. CBlobResult blobs;
  33. int i;
  34. CBlob *currentBlob;
  35. // find blobs in image
  36. blobs = CBlobResult( originalThr, NULL, 255 );
  37. blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );
  38. // display filtered blobs
  39. cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );
  40. for (i = 0; i < blobs.GetNumBlobs(); i++ )
  41. {
  42. currentBlob = blobs.GetBlob(i);
  43. currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
  44. }
  45. cvShowImage( wndname, displayedImage );
  46. }
  47. int main( int argc, char** argv )
  48. {
  49. param1 = 100;
  50. param2 = 2000;
  51. // open input image
  52. original = cvLoadImage("pic6.png",0);
  53. cvNamedWindow("input");
  54. cvShowImage("input", original );
  55. cvNamedWindow(wndname, 0);
  56. cvCreateTrackbar( tbarname1, wndname, &param1, 255, on_trackbar );
  57. cvCreateTrackbar( tbarname2, wndname, &param2, 30000, on_trackbar );
  58. // Call to update the view
  59. for(;;)
  60. {
  61. int c;
  62. // Call to update the view
  63. on_trackbar(0);
  64. c = cvWaitKey(0);
  65. if( c == 27 )
  66. break;
  67. }
  68. cvReleaseImage( &original );
  69. cvReleaseImage( &originalThr );
  70. cvReleaseImage( &displayedImage );
  71. cvDestroyWindow( wndname );
  72. return 0;
  73. }