PageRenderTime 117ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/20110425/Modality/main.cpp

https://github.com/itrufeng/learncv
C++ | 50 lines | 35 code | 1 blank | 14 comment | 0 complexity | 61524bea2d13c4b07a6ec3afdc4be508 MD5 | raw file
  1. /*
  2. * main.cpp
  3. *
  4. * Created on: 2011-4-25
  5. * Author: egame
  6. */
  7. #include <opencv/cv.h>
  8. #include <opencv/highgui.h>
  9. int main(int argc, char **argv) {
  10. // intit
  11. IplImage *srcImage;
  12. cvNamedWindow("srcImage",CV_WINDOW_AUTOSIZE);
  13. IplImage *erodeImage;
  14. cvNamedWindow("erodeImage",CV_WINDOW_AUTOSIZE);
  15. IplImage *dilateImage;
  16. cvNamedWindow("dilateImage",CV_WINDOW_AUTOSIZE);
  17. IplImage *gaojiImage;
  18. cvNamedWindow("gaojiImage",CV_WINDOW_AUTOSIZE);
  19. // vaildate
  20. assert(argv[1]);
  21. // load image
  22. srcImage = cvLoadImage(argv[1],CV_LOAD_IMAGE_ANYCOLOR);
  23. cvShowImage("srcImage",srcImage);
  24. // 自定义核
  25. IplConvKernel *k = cvCreateStructuringElementEx(9,9,1,1,CV_SHAPE_ELLIPSE,NULL);
  26. // 腐蚀
  27. erodeImage = cvCreateImage(cvGetSize(srcImage),srcImage->depth,srcImage->nChannels);
  28. cvErode(srcImage,erodeImage,k,1);
  29. cvShowImage("erodeImage",erodeImage);
  30. // 膨胀
  31. dilateImage = cvCreateImage(cvGetSize(srcImage),srcImage->depth,srcImage->nChannels);
  32. cvDilate(srcImage,dilateImage,k,1);
  33. cvShowImage("dilateImage",dilateImage);
  34. // 高级形态 更通用
  35. gaojiImage = cvCreateImage(cvGetSize(srcImage),srcImage->depth,srcImage->nChannels);
  36. cvMorphologyEx(srcImage,gaojiImage,NULL,k,CV_MOP_OPEN,1);
  37. cvShowImage("gaojiImage",gaojiImage);
  38. // release
  39. cvWaitKey(0);
  40. cvDestroyWindow("gaojiImage");
  41. cvReleaseImage(&gaojiImage);
  42. cvDestroyWindow("dilateImage");
  43. cvReleaseImage(&dilateImage);
  44. cvDestroyWindow("erodeImage");
  45. cvReleaseImage(&erodeImage);
  46. cvDestroyWindow("srcImage");
  47. cvReleaseImage(&srcImage);
  48. return 0;
  49. }