Skip to content

Commit

Permalink
Adding example 12-02
Browse files Browse the repository at this point in the history
  • Loading branch information
Prasanna Krishnasamy committed May 21, 2017
1 parent 7d8a413 commit 8ecfa9b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_executable( example_11-01 example_11-01.cpp )
add_executable( example_11-02 example_11-02.cpp )
add_executable( example_11-03 example_11-03.cpp )
add_executable( example_12-01 example_12-01.cpp )
add_executable( example_12-02 example_12-02.cpp )
add_executable( example_16-01 example_16-01.cpp )

target_link_libraries( example_02-01 ${OpenCV_LIBS} )
Expand Down Expand Up @@ -65,6 +66,7 @@ target_link_libraries( example_11-01 ${OpenCV_LIBS} )
target_link_libraries( example_11-02 ${OpenCV_LIBS} )
target_link_libraries( example_11-03 ${OpenCV_LIBS} )
target_link_libraries( example_12-01 ${OpenCV_LIBS} )
target_link_libraries( example_12-02 ${OpenCV_LIBS} )
target_link_libraries( example_16-01 ${OpenCV_LIBS} )


Expand Down
44 changes: 44 additions & 0 deletions example_12-02.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Example 12-2. Using cv::HoughCircles() to return a sequence of circles found in a
// grayscale image

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {

if(argc != 2) {
cout << "Hough Circle detect\nUsage: " <<argv[0] <<" <imagename>\n" << endl;
return -1;
}

cv::Mat src, image;

src = cv::imread( argv[1], 1 );
if( src.empty() ) { cout << "Cannot load " << argv[1] << endl; return -1; }

cv::cvtColor(src, image, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(image, image, Size(5,5), 0, 0);

vector<cv::Vec3f> circles;
cv::HoughCircles(image, circles, cv::HOUGH_GRADIENT, 2, image.cols/4);

for( size_t i = 0; i < circles.size(); ++i ) {
cv::circle(
src,
cv::Point(cvRound(circles[i][0]), cvRound(circles[i][1])),
cvRound(circles[i][2]),
cv::Scalar(0,0,255),
2,
cv::LINE_AA
);
}

cv::imshow( "Hough Circles", src);
cv::waitKey(0);

return 0;
}

0 comments on commit 8ecfa9b

Please sign in to comment.