P36霍夫直线检测

  • Post author:
  • Post category:其他


(一)知识点

函数输入为一幅二值图像(有很多待检测点),其中一些点排列后形成直线,通常这是一幅边缘图像,比如来自Sobel算子或Canny算子。函数的输出是cv::Vec3f的向量,每个元素都是代表检测到的直线的浮点数(ρ, θ,vote)。函数的作法是先求出原图像中每点的极坐标方程,若相交于一点的极坐标曲线的个数大于最小投票数,则将该点(ρ, θ)(参数坐标系点)放入输出向量。

注意CV中的坐标系发生了改变(0°垂直,90°水平,原点在右上角)


(16条消息) opencv 关于霍夫变换中pt1,pt2点设定问题_Gargamel97的博客-CSDN博客


http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm

(霍夫变换原理)▲经典霍夫变换和多尺度霍夫变换

(二)API

①HoughLines()【标准霍夫直线检测】

void HoughLines( InputArray image, OutputArray lines,
                              double rho, double theta, int threshold,
                              double srn = 0, double stn = 0,
                              double min_theta = 0, double max_theta = CV_PI );

void cv::HoughLines

(

InputArray image

, //8位,单通道二值源图像。该函数可以修改图像。


OutputArray lines

,//输出直线vector(ρ,θ) or (ρ,θ,votes)

//ρ是距坐标原点的距离,

//θ是以弧度表示的线旋转角度(0∼垂直直线,π/2∼水平直线)

//votes 曲线交点累加计数


double     rho

, //以像素为单位的累加器的距离分辨率。 推荐用1.0;


double     theta

, //以弧度表示的累加器角度分辨率。 CV_PI/180


int     threshold

, //累加计数大于此阈值才返回 累加平面的阈值参数,int类型,超过设定阈值才被检测出线段,值越大,基本上意味着检出的线段越长,检出的线段个数越少。根据情况推荐先用100试试;


double     srn

= 0,


double     stn

= 0,


double     min_theta

= 0, //检查线条的最小角度。必须介于0和maxθ之间。


double     max_theta

= CV_PI  //要检查线条的最大角度。必须介于minθ和CV_PI之间。

)

Parameters

image    8-bit, single-channel binary source image. The image may be modified by the function.

lines    Output vector of lines. Each line is represented by a 2 or 3 element vector (ρ,θ) or (ρ,θ,votes) . ρ is the distance from the coordinate origin (0,0) (top-left corner of the image). θ is the line rotation angle in radians ( 0∼vertical line,π/2∼horizontal line ). votes is the value of accumulator.

rho    Distance resolution of the accumulator in pixels.

theta    Angle resolution of the accumulator in radians.

threshold    Accumulator threshold parameter. Only those lines are returned that get enough votes ( >threshold ).


srn


For the multi-scale Hough transform, it is a divisor for the distance resolution rho . The coarse accumulator distance resolution is rho and the accurate accumulator resolution is rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these parameters should be positive.


stn    For the multi-scale Hough transform, it is a divisor for the distance resolution theta.

min_theta    For standard and multi-scale Hough transform, minimum angle to check for lines. Must fall between 0 and max_theta.

max_theta    For standard and multi-scale Hough transform, maximum angle to check for lines. Must fall between min_theta and CV_PI.


(16条消息) 直线检测:霍夫变换 HoughLines 和 HoughLinesP_智能码农的博客-CSDN博客


(16条消息) 标准HoughLines()变换_苦逼的程序猿-CSDN博客_houghlines

②cvRound()【将float数据类型取整为int型】

③HoughlinesP()【统计概率霍夫线变换】

void HoughLinesP( InputArray image, OutputArray lines,
                               double rho, double theta, int threshold,
                               double minLineLength = 0, double maxLineGap = 0 );

(三)代码演示

(四)运行效果



版权声明:本文为m0_54641001原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。