opencv 霍夫变换检测圆
2017-02-24 16:25
507 查看
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
const int kvalue = 15;//双边滤波邻域大小
int main()
{
Mat src_color=imread("1.jpg");
imshow("原图-彩色", src_color);
//声明一个三通道图像,像素值全为0,用来将霍夫变换检测出的圆画在上面
Mat dst(src_color.size(), src_color.type());
dst = Scalar::all(0);
Mat src_gray;//彩色图像转化成灰度图
cvtColor(src_color, src_gray, COLOR_BGR2GRAY);
imshow("原图-灰度", src_gray);
imwrite("src_gray.png", src_gray);
Mat bf;//对灰度图像进行双边滤波
bilateralFilter(src_gray, bf, kvalue, kvalue * 2, kvalue / 2);
imshow("灰度双边滤波处理", bf);
imwrite("src_bf.png", bf);
vector<Vec3f> circles;//声明一个向量,保存检测出的圆的圆心坐标和半径
HoughCircles(bf, circles, CV_HOUGH_GRADIENT, 1.5, 20, 130, 38, 10, 50);//霍夫变换检测圆
cout << "x=\ty=\tr=" << endl;
for (size_t i = 0; i < circles.size(); i++)//把霍夫变换检测出的圆画出来
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
circle(dst, center, 0, Scalar(0, 255, 0), -1, 8, 0);
circle(dst, center, radius, Scalar(0, 0, 255), 1, 8, 0);
cout << cvRound(circles[i][0]) << "\t" << cvRound(circles[i][1]) << "\t"
<< cvRound(circles[i][2]) << endl;//在控制台输出圆心坐标和半径
}
imshow("特征提取", dst);
imwrite("dst.png", dst);
waitKey(0);
}
using namespace cv;
using namespace std;
const int kvalue = 15;//双边滤波邻域大小
int main()
{
Mat src_color=imread("1.jpg");
imshow("原图-彩色", src_color);
//声明一个三通道图像,像素值全为0,用来将霍夫变换检测出的圆画在上面
Mat dst(src_color.size(), src_color.type());
dst = Scalar::all(0);
Mat src_gray;//彩色图像转化成灰度图
cvtColor(src_color, src_gray, COLOR_BGR2GRAY);
imshow("原图-灰度", src_gray);
imwrite("src_gray.png", src_gray);
Mat bf;//对灰度图像进行双边滤波
bilateralFilter(src_gray, bf, kvalue, kvalue * 2, kvalue / 2);
imshow("灰度双边滤波处理", bf);
imwrite("src_bf.png", bf);
vector<Vec3f> circles;//声明一个向量,保存检测出的圆的圆心坐标和半径
HoughCircles(bf, circles, CV_HOUGH_GRADIENT, 1.5, 20, 130, 38, 10, 50);//霍夫变换检测圆
cout << "x=\ty=\tr=" << endl;
for (size_t i = 0; i < circles.size(); i++)//把霍夫变换检测出的圆画出来
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
circle(dst, center, 0, Scalar(0, 255, 0), -1, 8, 0);
circle(dst, center, radius, Scalar(0, 0, 255), 1, 8, 0);
cout << cvRound(circles[i][0]) << "\t" << cvRound(circles[i][1]) << "\t"
<< cvRound(circles[i][2]) << endl;//在控制台输出圆心坐标和半径
}
imshow("特征提取", dst);
imwrite("dst.png", dst);
waitKey(0);
}
相关文章推荐
- Opencv学习---霍夫变换检测圆的基本原理
- opencv 霍夫变换检测直线中pt1、pt2点的确定
- opencv 霍夫变换检测直线 例程中的1000
- opencv 霍夫变换检测直线
- opencv 霍夫变换检测直线(转)
- opencv 霍夫变换检测圆环
- OpenCV学习18--霍夫变换检测直线
- 霍夫变换直线检测houghlines及opencv的实现分析
- opencv 霍夫变换检测直线
- opencv 霍夫变换检测直线中pt1、pt2点的确定
- 【opencv练习23 - 霍夫直线变换——直线检测】
- Opencv中 霍夫线变换检测直线中pt1、pt2点的确定
- opencv圆形检测,霍夫变换不稳定
- OpenCV 应用边缘检测与霍夫线变换实现旋转角度检测
- OpenCV学习笔记-霍夫线变换2
- OpenCV学习之基于Hough变换的直线检测
- OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑
- opencv 从摄像头读取检测直线(霍夫变化)
- 霍夫变换直线检测理解
- Hough变换检测椭圆 附带matlab与opencv代码