#include <opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include"opencv2/highgui/highgui.hpp"
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<time.h>
#include<vector>
using namespace std;
using namespace cv;
void printvector(vector<int>vec)
{
for (vector<int>::iterator it = vec.begin(); it != vec.end(); it++)
cout << *it << "";
}
void DrawA(std::vector<Point>vec, Mat src)
{
for (int i = 0; i < vec.size(); i++)
cv::line(src, vec[i], vec[(i + 1) % vec.size()], Scalar(0, 255, 0));
imshow("src", src);
}
int main()
{
Mat srcImage = imread("C:/Users/离子键/source/repos/Project8/1.jpg");
Mat midImage, dstImage;
imshow("【原始图】", srcImage);
cvtColor(srcImage,midImage,COLOR_BGR2GRAY);
GaussianBlur(midImage,midImage,Size(9,9),2,2);
vector<Vec3f>circles;
HoughCircles(midImage,circles, HOUGH_GRADIENT,1.5,10,200,100,0,0);
for (int i = 0; i < circles.size(); i++)
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
std::cout << center.x << " " << center.y << std::endl;
int radius = cvRound(circles[i][2]);
std::cout << radius << std::endl;
circle(srcImage, center, 5, Scalar(0, 255, 0), 2, 8, 0);
circle(srcImage, center, radius, Scalar(0, 255, 0), 1, 8, 0);
}
imshow("【效果图】",srcImage);
vector<int>v1;
Mat src_1 = Mat::zeros(600, 600,CV_8UC3);
vector<Point>v_p;
Point p1(20, 50);
Point p2(2, 450);
Point p3(230, 950);
Point p4(60, 250);
v_p.push_back(p1);
v_p.push_back(p2);
v_p.push_back(p3);
v_p.push_back(p4);
DrawA(v_p, src_1);
for (int i = 0; i < 5; i++)
{
v1.push_back(i);
}
printvector(v1);
waitKey(0);
return 0;
}
一开始
可能是半径参数太死了:搞得下面没有圆出现
然后师兄帮我改了一下,输出一些值,看看是什么问题:
然后左上角出现了一点点绿色的圆 。。。他说你可以用滑动条去调节参数,我们战队很少用这个霍夫圆,也不用理他。。
原版介绍: