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

/examples/opencv/src/circle_detection.cpp

https://gitlab.com/juan-cardelino/misc_projects
C++ | 29 lines | 26 code | 3 blank | 0 comment | 1 complexity | b11212efa4a5d6701a599fec54328684 MD5 | raw file
  1. #include <cv.h>
  2. #include <highgui.h>
  3. #include <math.h>
  4. int main(int argc, char** argv)
  5. {
  6. IplImage* img = cvLoadImage("view_0002.png", 1);;
  7. IplImage* gray = cvCreateImage(cvGetSize(img), 8, 1);
  8. CvMemStorage* storage = cvCreateMemStorage(0);
  9. cvCvtColor(img, gray, CV_BGR2GRAY);
  10. cvSmooth(gray, gray, CV_GAUSSIAN, 9, 9);
  11. CvSeq* circles = cvHoughCircles(gray, storage,
  12. CV_HOUGH_GRADIENT, 2, 20, 10, 5, 5, 20);
  13. int i;
  14. for (i = 0; i < circles->total; i++)
  15. {
  16. float* p = (float*)cvGetSeqElem( circles, i );
  17. cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])),
  18. 3, CV_RGB(0,255,0), -1, 8, 0 );
  19. cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])),
  20. cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
  21. }
  22. cvNamedWindow( "circles", 1 );
  23. cvShowImage( "circles", img );
  24. cvWaitKey(0);
  25. return 0;
  26. }