Opencvsharp学习(二二):霍夫变换----直线检测

霍夫变换:霍夫变换是图像处理中的一种特征提取技术
有两种,霍夫直线检测,霍夫圆检测
霍夫直线检测
HoughLines:标准霍夫变换
HoughLinesP:累计概率霍夫变换

函数原型
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 表示经典霍夫变换

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);
      }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值