霍夫变换:霍夫变换是图像处理中的一种特征提取技术
有两种:霍夫直线检测,霍夫圆检测
1,霍夫直线检测
HoughLines: 标准霍夫变换
HoughLinesP: 累计概率霍夫变换
函数原型
1.1,HoughLines:标准霍夫直线检测
public static LineSegmentPolar[] HoughLines(InputArray image,double rho,double theta,int threshold,double srn = 0,double stn = 0);
返回值:LineSegmentPolar类型数组,包括,线长,角度
image: 输入图片
rho: 直线搜索时的单位半径(像素单位)
theta: 直线搜索是的
threshold: 阈值,指搜索直线时,它在累计平面必须达到的阈值,大于threshold的值才会被返回
srn 对于多尺度霍夫变换,它是距离分辨率的因子。[默认值为0] 如果不是设置0 表示经典霍夫变换
stn 对于多尺度霍夫变换,它是距离分辨率的因子。[默认值为0] 如果不是设置0 表示经典霍夫变换
1.2,HoughLinesP: 累计概率霍夫变换:
函数原型:
public static LineSegmentPoint[] HoughLinesP(InputArray image,double rho,double theta,int threshold,double minLineLength = 0,double maxLineGap = 0);
返回值: LineSegmentPoint类型的数组
image: 输入图像
rho: 直线搜索时的单位半径(像素单位)
theta: 直线搜索是的
threshold: 阈值,指搜索直线时,它在累计平面必须达到的阈值,大于threshold的值才会被返回
minLineLength : 最小线长度。比这个短的线条被忽略
maxLineGap : 同一条线上的点之间连接它们的最大允许间隙。[默认值为0]
关于标准直线检测 HoughLines 返回值 LineSegmentPolar[] 的处理
for (int i = 0; i < lineing.Length; i++){double rho = lineing[i].Rho;//线长double theta = lineing[i].Theta;//角度Point pt1 = new Point();Point pt2 = new Point();double a = Math.Cos(theta);double b = Math.Sin(theta);double x0 = a * rho, y0 = b * rho;pt1.X = (int)Math.Round(x0 + 600 * (-b));pt1.Y = (int)Math.Round(y0 + 600 * a);pt2.X = (int)Math.Round(x0 - 600 * (-b));pt2.Y = (int)Math.Round(y0 - 600 * a);Cv2.Line(Result1, pt1, pt2, Colar, 4,LineTypes.Link8);}
关于概率直线检测HoughLinesP的返回值LineSegmentPoint[] 的处理
for (int i = 0; i < Line.Count(); i++){Point p1 = Line[i].P1;Point p2 = Line[i].P2;Cv2.Line(Result,p1,p2, Colar,4,LineTypes.Link8);}
