OpenCV学习笔记(十四)圆检测技术
2016-12-15 20:54
211 查看
圆检测技术:
圆检测技术目前用处还是特别的广泛的,锅炉、管道等类似的情况,我们不能切开或者打孔去测试流量,温度等参数。这是我们可以在管道上画一个圆,用摄像机去检测圆中心,进而测试出我们需要的信息。
对于一个圆,就需要用三个参数来确定。使用Hough梯度法的依据是圆心一定出现在圆上的每个点的模向量上,圆上点的模向量的交点就是圆心的所在位置。Hough梯度法的第一步就是找到这些圆心,这样三维的累加平面就转化为二维累加平面。第二步就是根据所有候选中心的边缘非零像素对其的支持程度来确定半径。
void HoughCircles(InputArray image,
OutputArray circles, int method, double dp,
double minDist, double param1=100, doubleparam2=100,
int minRadius=0, int maxRadius=0 )
image – 8-bit, single-channel, grayscale input image.
circles – Output vector of found circles. Each vector is encoded as a 3-element floating-point vector
.圆心和圆
method – 目前只有霍夫梯度法可用,HOUGH_GRADIENT。
dp – 用来检测圆心的累加器图像的分辨率与输入图像之比的导数。. For example, if dp=1 ,
the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height.
minDist – Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition
to a true one. If it is too large, some circles may be missed.
param1 – First method-specific parameter. In case of HOUGH_GRADIENT ,
it is the higher threshold of the two passed to the Canny() edge
detector (the lower one is twice smaller).
param2 – Second method-specific parameter. In case of HOUGH_GRADIENT ,
it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
minRadius – Minimum circle radius.
maxRadius – Maximum circle radius.
使用此函数,可以很容易的检测出圆的中心,但是它找不到合适的圆半径。我们可以通过minRadius和maxRadius指定最小和最大的圆半径,来辅助检测的效果。或者直接返回0,然后用额外的步骤确定圆的半径。
void circle(Mat& img, Point center, int radius,
const Scalar& color, int thickness=1, int lineType=8, int shift=0)
img – Image where the circle is drawn.
center – Center of the circle.
radius – Radius of the circle.
color – Circle color.
thickness – Thickness of the circle outline, if positive. Negative thickness means that a filled
circle is to be drawn.
lineType – Type of the circle boundary.
See the line() description.
Type=8/4/CV_AA
shift – Number of fractional bits in the coordinates of the center and in the radius value. shift =0
实例程序:
效果图:
Hough梯度法的缺点:同心圆难以检测;临近圆易出错;Sobel导数会产生噪声。
圆检测技术目前用处还是特别的广泛的,锅炉、管道等类似的情况,我们不能切开或者打孔去测试流量,温度等参数。这是我们可以在管道上画一个圆,用摄像机去检测圆中心,进而测试出我们需要的信息。
对于一个圆,就需要用三个参数来确定。使用Hough梯度法的依据是圆心一定出现在圆上的每个点的模向量上,圆上点的模向量的交点就是圆心的所在位置。Hough梯度法的第一步就是找到这些圆心,这样三维的累加平面就转化为二维累加平面。第二步就是根据所有候选中心的边缘非零像素对其的支持程度来确定半径。
void HoughCircles(InputArray image,
OutputArray circles, int method, double dp,
double minDist, double param1=100, doubleparam2=100,
int minRadius=0, int maxRadius=0 )
image – 8-bit, single-channel, grayscale input image.
circles – Output vector of found circles. Each vector is encoded as a 3-element floating-point vector
.圆心和圆
method – 目前只有霍夫梯度法可用,HOUGH_GRADIENT。
dp – 用来检测圆心的累加器图像的分辨率与输入图像之比的导数。. For example, if dp=1 ,
the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height.
minDist – Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition
to a true one. If it is too large, some circles may be missed.
param1 – First method-specific parameter. In case of HOUGH_GRADIENT ,
it is the higher threshold of the two passed to the Canny() edge
detector (the lower one is twice smaller).
param2 – Second method-specific parameter. In case of HOUGH_GRADIENT ,
it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
minRadius – Minimum circle radius.
maxRadius – Maximum circle radius.
使用此函数,可以很容易的检测出圆的中心,但是它找不到合适的圆半径。我们可以通过minRadius和maxRadius指定最小和最大的圆半径,来辅助检测的效果。或者直接返回0,然后用额外的步骤确定圆的半径。
void circle(Mat& img, Point center, int radius,
const Scalar& color, int thickness=1, int lineType=8, int shift=0)
img – Image where the circle is drawn.
center – Center of the circle.
radius – Radius of the circle.
color – Circle color.
thickness – Thickness of the circle outline, if positive. Negative thickness means that a filled
circle is to be drawn.
lineType – Type of the circle boundary.
See the line() description.
Type=8/4/CV_AA
shift – Number of fractional bits in the coordinates of the center and in the radius value. shift =0
实例程序:
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main(int args,char** argv) { Mat srcImage = imread("D:\\5.jpg"); if (!srcImage.data) return -1; imshow("srcImage", srcImage); Mat srcGray; cvtColor(srcImage, srcGray, COLOR_BGR2GRAY); //高斯平滑滤波 GaussianBlur(srcGray, srcGray, Size(9, 9), 2,2); vector<Vec3f> circles; //Hough圆检测 HoughCircles(srcGray, circles, HOUGH_GRADIENT,1,srcGray.rows/8,200,100,0,0); //将得到的结果绘图 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(srcImage, center, 3, Scalar(0, 255, 0), -1, 8, 0); //检测圆轮廓 circle(srcImage, center, radius, Scalar(120, 120, 120), 3, 8, 0); } imshow("HoughResult", srcImage); waitKey(0); return 0; }原图:
效果图:
Hough梯度法的缺点:同心圆难以检测;临近圆易出错;Sobel导数会产生噪声。
相关文章推荐
- 基于haar+adaboost的人脸检测、深度学习的人脸识别技术应用综述
- 在PHP中应用Ajax技术检测用户名
- 微软使用类似僵尸网络的技术进行Office2010漏洞检测
- 虚拟机检测技术剖析
- 面部特征点检测的关键技术
- 车牌识别技术详解一(可用于车牌识别,字符识别,人脸检测,验证码识别等等成熟领域)
- SQL注入技术和跨站脚本攻击的检测(1)
- 高级碰撞检测技术
- 秋色园QBlog技术原理解析:性能优化篇:缓存总有失效时,持续的缓存方案(十四)
- [原创]WCF技术剖析之十四:泛型数据契约和集合数据契约(下篇)
- javascript客户端检测技术
- 基于RealSense的坐姿检测技术
- JavaScript 常见安全漏洞和自动化检测技术
- 使用injectso 技术注入mtrace,对进程进行内存检测 源码
- 微信域名检测接口,微信域名检测API,微信域名防封技术Q510668789
- USB如何检测到设备的插入-usb技术入门教程1
- SYN***的基本原理、工具及检测方法以及防范技术
- OpenCV学习之旅2—边缘检测技术
- 恶意软件反检测技术简介:模拟器超限技术