forked from oreillymedia/Learning-OpenCV-3_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prasanna Krishnasamy
committed
May 21, 2017
1 parent
7d8a413
commit 8ecfa9b
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |