/src/Chapter06/cvHoughCircles.cpp

https://github.com/yourtion/LearningOpenCV · C++ · 32 lines · 18 code · 7 blank · 7 comment · 1 complexity · 86c00500d1d03e3650be314c3ae1cea1 MD5 · raw file

  1. //
  2. // cvHoughCircles.cpp
  3. // LearningOpenCV
  4. //
  5. // Created by YourtionGuo on 7/28/16.
  6. // Copyright © 2016 Yourtion. All rights reserved.
  7. //
  8. #include <iostream>
  9. #include <highgui.h>
  10. #include <cv.h>
  11. int main(int argc, const char * argv[]) {
  12. IplImage* image = cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
  13. CvMemStorage* storage = cvCreateMemStorage(0);
  14. cvSmooth(image, image, CV_GAUSSIAN, 5, 5);
  15. CvSeq* results = cvHoughCircles( image, storage, CV_HOUGH_GRADIENT, 2, image->width/10 );
  16. for ( int i = 0; i < results->total ; i++ ) {
  17. float* p = (float *) cvGetSeqElem( results, i);
  18. CvPoint pt = cvPoint( cvRound(p[0]), cvRound(p[1]) );
  19. cvCircle(image, pt, cvRound(p[2]), CV_RGB(0xff, 0xff, 0xff));
  20. }
  21. cvNamedWindow( "cvHoughCircles", 1 );
  22. cvShowImage( "cvHoughCircles", image );
  23. cvWaitKey(0);
  24. return 0;
  25. }