#include<opencv2\highgui\highgui.hpp>
#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
char *output_title = "output Image";
Mat src, canny_dst, gray_image, dst;
//霍夫圆检测前先进行中值滤波
int main()
{
src = imread("E:\\vs2015\\opencvstudy\\1.jpg", 1);
if (src.empty())
{
cout << "could not load the src image!" << endl;
return -1;
}
char *input_title = "input Image";
imshow(input_title, src);
//中值滤波
Mat median_image;
medianBlur(src, median_image, 3);
Mat gray_image;
cvtColor(median_image, gray_image, CV_BGR2GRAY);
//霍夫检测
Mat hc_image;
vector<Vec3f> pcircles;
HoughCircles(gray_image, pcircles, CV_HOUGH_GRADIENT, 1, 10, 100, 30, 5, 50);
src.copyTo(hc_image);
for (int i = 0; i < pcircles.size(); i++)
{
Vec3f cc = pcircles[i];
circle(hc_image, Point(cc[0], cc[1]), cc[2], Scalar(0, 0, 255), 2, LINE_AA);
circle(hc_image, Point(cc[0], cc[1]), 2, Scalar(198, 23, 255), 2, LINE_AA);
}
imshow("result", hc_image);
waitKey(0);
return 0;
}